本文整理汇总了C#中UnitOfWork.Repository方法的典型用法代码示例。如果您正苦于以下问题:C# UnitOfWork.Repository方法的具体用法?C# UnitOfWork.Repository怎么用?C# UnitOfWork.Repository使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UnitOfWork
的用法示例。
在下文中一共展示了UnitOfWork.Repository方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: FindStoryById
public void FindStoryById()
{
using (IDataContextAsync myStoriesFakeContext = new MyStoriesFakeContext())
using (IUnitOfWorkAsync unitOfWork = new UnitOfWork(myStoriesFakeContext))
{
var groups = new List<Group>
{
new Group {Id = 1, Name = "Group1", Description = "Group Desc", ObjectState = ObjectState.Added},
new Group {Id = 2, Name = "Group2", Description = "Group Desc", ObjectState = ObjectState.Added}
};
foreach (var g in groups)
{
unitOfWork.Repository<Group>().Insert(g);
}
unitOfWork.Repository<Story>().Insert(new Story { Id = 1, Description = "Desc", Content = "Content", Title = "Title", PostedOn = DateTime.Today, Groups = groups });
unitOfWork.Repository<Story>().Insert(new Story { Id = 2, Description = "Desc", Content = "Content", Title = "Title", PostedOn = DateTime.Today, Groups = groups });
unitOfWork.Repository<Story>().Insert(new Story { Id = 3, Description = "Desc", Content = "Content", Title = "Title", PostedOn = DateTime.Today, Groups = groups });
unitOfWork.SaveChanges();
var story = unitOfWork.Repository<Story>().Find(2);
Assert.IsNotNull(story);
Assert.AreEqual(2, story.Id);
}
}
示例2: CapNhatThongTinCaNhan
public string CapNhatThongTinCaNhan(string ip_str_user_name, string ip_str_ho_ten, string ip_str_so_dien_thoai, string ip_str_phong_ban)
{
string result = "CapNhatThongTinCaNhanThanhCong";
UnitOfWork uow = new UnitOfWork();
HT_USER v_ht_user = uow.Repository<HT_USER>().Query().Filter(x => x.USER_NAME.Contains(ip_str_user_name)).FirstOrDefault();
if (v_ht_user == null) return "CapNhatThongTinCaNhanThatBai";
v_ht_user.HO_TEN = ip_str_ho_ten;
v_ht_user.SDT = ip_str_so_dien_thoai;
v_ht_user.PHONG = ip_str_phong_ban;
v_ht_user.State = EDataState.Modified;
uow.Repository<HT_USER>().Update(v_ht_user);
uow.Save();
return result;
}
示例3: DeepLoadProductWithSupplier
public void DeepLoadProductWithSupplier()
{
using (IDataContextAsync northwindFakeContext = new NorthwindFakeContext())
using (IUnitOfWork unitOfWork = new UnitOfWork(northwindFakeContext))
{
unitOfWork.Repository<Supplier>().Insert(new Supplier {SupplierID = 1, CompanyName = "Nokia", City = "Tampere", Country = "Finland", ContactName = "Stephen Elop", ContactTitle = "CEO", ObjectState = ObjectState.Added});
unitOfWork.Repository<Product>().Insert(new Product {ProductID = 2, Discontinued = true, ProductName = "Nokia Lumia 1520", SupplierID = 1, ObjectState = ObjectState.Added});
unitOfWork.SaveChanges();
var product = unitOfWork.Repository<Product>().Find(2);
Assert.IsNotNull(product);
}
}
示例4: GetMovieByIDTest
public void GetMovieByIDTest()
{
using (IUnitOfWork unitOfWork = new UnitOfWork(new FlickSomeContext()))
{
var movie = unitOfWork.Repository<Movie>().GetMovieById(2);
movie.State = Infrastructure.Enums.ObjectState.Deleted;
unitOfWork.Save();
movie = unitOfWork.Repository<Movie>().GetMovieById(2);
Assert.IsNull(movie); ;
}
}
示例5: getTuDienById
//public TuDienModel GetTuDienByMaLoai(string ip_str_ma_loai) {
// UnitOfWork uow = new UnitOfWork();
// var v_tudien = uow.Repository<CM_DM_TU_DIEN>().Query()
// .Filter(x => x.MA_TU_DIEN == ip_str_ma_loai)
// .OrderBy(x => x.OrderByDescending(y => y.TEN)).FirstOrDefault();
// return v_tudien.CopyAs<TuDienModel>();
//}
public TuDienModel getTuDienById(Guid ip_id_tu_dien)
{
UnitOfWork uow = new UnitOfWork();
var v_tu_dien = uow.Repository<CM_DM_TU_DIEN>().Query()
.Filter(x => x.ID == ip_id_tu_dien).FirstOrDefault();
return v_tu_dien.CopyAs<TuDienModel>();
}
示例6: GetCurrentLanguage
// I think we don't need to preload languages. the Native language for current user will be loaded with first access to localize resource.
// And Usual user don't change the language during his session.
// Furthermore not necessary to load ALL languages. As result - low performance during loading app. And also we load to much in memory.
public static string GetCurrentLanguage(HttpContextBase context)
{
var culture = Localization.DefaultLocalization;
if (context.Request.Cookies["lang"] == null)
{
//add default
context.Response.Cookies.Add(new HttpCookie("lang", culture));
}
else
{
culture = context.Request.Cookies["lang"].Value;
}
// Better to load from db actual data
using (var unitOfWork = new UnitOfWork(new PlutonContext()))
{
if (unitOfWork.Repository<LocalizationResource>().Query().Filter(x => x.Culture == culture).GetOne() ==
null)
{
context.Response.Cookies.Remove("lang");
context.Response.Cookies.Add(new HttpCookie("lang", DefaultLocalization));
}
}
return culture;
}
示例7: Get
public IChart Get(string strChartId, string strDrillBy, string strUserName, string strSearchParameter)
{
ChartID idSelected;
IChart chartToLoad = null;
TBL_CHART dbChart = null;
IUnitOfWork uo = new UnitOfWork("CCATDBEntities");
idSelected = (ChartID)Enum.Parse(typeof(ChartID), strChartId, true);
dbChart = uo.Repository<TBL_CHART>().GetAll().Where(c => c.ChartID == strChartId && c.IsActive == true).SingleOrDefault();
if (dbChart.TypeOfChart == "Chart")
{
chartToLoad = new Chart() { SearchParameters = new string[] { strSearchParameter}, BGAlpha = dbChart.BgAlpha, BGColor = dbChart.BgColor, CanvasBGAlpha = dbChart.CanvasBgAlpha, CanvasBGColor = dbChart.CanvasBgColor, Caption = dbChart.Caption, SWF = dbChart.SWFile, NumberSuffix = dbChart.NumberSuffix, PieRadius = dbChart.PieRadius, showLabels = dbChart.ShowLabels, showLegend = dbChart.ShowLegend, XaxisName = dbChart.XaxisName, YaxisName = dbChart.YaxisName, Id = idSelected, enableRotation = dbChart.EnableRotation, DrillChartIds = (string.IsNullOrEmpty(dbChart.DrillLevelChartIDs)) ? "" : dbChart.DrillLevelChartIDs, DrillOverride = false, DrillBy = (string.IsNullOrEmpty(strDrillBy)) ? "" : strDrillBy };
chartToLoad.LoadChart(strUserName);
chartToLoad.CreateChart();
}
else if (dbChart.TypeOfChart == "PieChart")
{
chartToLoad = new PieChart() { BGAlpha = dbChart.BgAlpha, BGColor = dbChart.BgColor, CanvasBGAlpha = dbChart.CanvasBgAlpha, CanvasBGColor = dbChart.CanvasBgColor, Caption = dbChart.Caption, SWF = dbChart.SWFile, NumberSuffix = dbChart.NumberSuffix, PieRadius = dbChart.PieRadius, showLabels = dbChart.ShowLabels, showLegend = dbChart.ShowLegend, XaxisName = dbChart.XaxisName, YaxisName = dbChart.YaxisName, Id = idSelected, enableRotation = dbChart.EnableRotation, DrillChartIds = (string.IsNullOrEmpty(dbChart.DrillLevelChartIDs)) ? "" : dbChart.DrillLevelChartIDs, DrillOverride = false, DrillBy = (string.IsNullOrEmpty(strDrillBy)) ? "" : strDrillBy };
((PieChart)chartToLoad).LoadChart();
((PieChart)chartToLoad).CreateChart();
}
else if (dbChart.TypeOfChart == "BarChart")
{
chartToLoad = new BarChart() { BGAlpha = dbChart.BgAlpha, BGColor = dbChart.BgColor, CanvasBGAlpha = dbChart.CanvasBgAlpha, CanvasBGColor = dbChart.CanvasBgColor, Caption = dbChart.Caption, SWF = dbChart.SWFile, NumberSuffix = dbChart.NumberSuffix, PieRadius = dbChart.PieRadius, showLabels = dbChart.ShowLabels, showLegend = dbChart.ShowLegend, XaxisName = dbChart.XaxisName, YaxisName = dbChart.YaxisName, Id = idSelected, enableRotation = dbChart.EnableRotation, DrillChartIds = (string.IsNullOrEmpty(dbChart.DrillLevelChartIDs)) ? "" : dbChart.DrillLevelChartIDs, DrillOverride = false, DrillBy = (string.IsNullOrEmpty(strDrillBy)) ? "" : strDrillBy };
((BarChart)chartToLoad).LoadChart();
((BarChart)chartToLoad).CreateChart();
}
return chartToLoad;
}
示例8: OnActionExecuting
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
using (var unitOfWork = new UnitOfWork(new PlutonContext()))
{
var routeDate = filterContext.RouteData;
var currentAction = routeDate.GetRequiredString("action");
var currentController = routeDate.GetRequiredString("controller");
var username = filterContext.HttpContext.User.Identity.Name;
var useragent = filterContext.HttpContext.Request.UserAgent;
var sessionId = string.Empty;
if (filterContext.HttpContext.Request.Cookies[".ASPXAUTH"] != null)
sessionId = filterContext.HttpContext.Request.Cookies[".ASPXAUTH"].Value;
var browser = filterContext.HttpContext.Request.Browser.Type;
var ip = filterContext.HttpContext.Request.UserHostAddress;
var url = filterContext.HttpContext.Request.RawUrl;
var accessLogItem = new AccessLogItem
{
DateTime = DateTime.Now,
Action = currentAction,
Controller = currentController,
Username = username,
Useragent = useragent,
SessionId = sessionId,
Browser = browser,
Ip = ip,
Url = url
};
unitOfWork.Repository<AccessLogItem>().Insert(accessLogItem);
unitOfWork.Commit();
}
base.OnActionExecuting(filterContext);
}
示例9: GetListMatHang
public List<DM_MAT_HANG> GetListMatHang()
{
using(var uow = new UnitOfWork())
{
return uow.Repository<DM_MAT_HANG>().GetAll().ToList();
}
}
示例10: GetListKhachHang
public List<DM_KHACH_HANG> GetListKhachHang()
{
using(var uow = new UnitOfWork())
{
return uow.Repository<DM_KHACH_HANG>().GetAll().ToList();
}
}
示例11: GetAllUsers
public IEnumerable<UserModel> GetAllUsers()
{
try
{
IUnitOfWork uo = new UnitOfWork("CCATDBEntities");
var data = from m in uo.Repository<aspnet_Membership>().GetAll()
from user in uo.Repository<aspnet_Users>().GetAll().Where(userRecord => userRecord.UserId == m.UserId)
select new UserModel(user.UserId);
return data;
}
catch (Exception ex)
{
throw ex;
}
}
示例12: AddCustomerTest
public void AddCustomerTest()
{
using(var dataContext = new ModelDataContext())
using (var unitOfWork = new UnitOfWork(dataContext) )
{
var customerID = Guid.NewGuid();
var customer = new Customer()
{
ID = Guid.NewGuid(),
Name = "BBC",
Address = "No.1 Bee Street",
City = "London",
Country = "UK",
Region = "AA",
Fax = "000000",
Phone = "00000000000",
PostalCode = "555555"
};
var customerRepository = unitOfWork.Repository<Customer>();
customerRepository.Insert(customer); ;
unitOfWork.SaveChanges();
var insertedCustomer = customerRepository.Find(customerID);
Assert.IsNotNull(insertedCustomer);
Assert.AreEqual(customerID, insertedCustomer.ID);
}
}
示例13: GetListKho
public List<DM_KHO> GetListKho()
{
using(var uow = new UnitOfWork())
{
return uow.Repository<DM_KHO>().GetAll().ToList();
}
}
示例14: AddPatientMedication
public ActionResult AddPatientMedication(patientmedication medication)
{
unitOfWork.Repository<patientmedication>().Insert(medication);
unitOfWork.Save();
unitOfWork = new UnitOfWork();
return PartialView("_PatientMedication", unitOfWork.Repository<patientmedication>().Filter(x => x.PatientId == medication.PatientId).Get());
}
示例15: AddPatientProblem
public ActionResult AddPatientProblem([Bind(Exclude = "Id")]patientproblem patientProblem)
{
int patientId = int.Parse(RouteData.Values["id"].ToString());
unitOfWork.Repository<patientproblem>().Insert(patientProblem);
unitOfWork.Save();
unitOfWork = new UnitOfWork();
return PartialView("_PatientProblem", unitOfWork.Repository<patientproblem>().Filter(x => x.PatientId == patientId).Get());
}