本文整理汇总了C#中UnitOfWork.Commit方法的典型用法代码示例。如果您正苦于以下问题:C# UnitOfWork.Commit方法的具体用法?C# UnitOfWork.Commit怎么用?C# UnitOfWork.Commit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UnitOfWork
的用法示例。
在下文中一共展示了UnitOfWork.Commit方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
static void Main(string[] args)
{
var dbContext = new ApplicationDbContext();
using (var uow = new UnitOfWork(dbContext))
{
// Creating user
// var user1 = new User { Login = "Anna", Password = "123" };
// var userRepo = new UserRepository(dbContext);
//userRepo.Create(user1);
//uow.Commit();
var userRepo = new UserRepository(dbContext);
var user1 = new User { Login = "Anna1", Password = "123" };
var user2 = new User { Login = "Anna2", Password = "123" };
// userRepo.Create(user1);
//userRepo.Create(user2);
// uow.Commit();
var users = userRepo.GetAll();
Console.WriteLine("All users count: " + users.Count());
var anna = userRepo.GetBy(user1.Login);
userRepo.Delete(anna);
uow.Commit();
users = userRepo.GetAll();
Console.WriteLine("All filtered users count: " + users.Count());
Console.ReadLine();
// Creating user article
var article1 = new Article { Title = "Article1", Body = "Article1 BodyText" };
var anna2 = userRepo.GetBy(user2.Login);
userRepo.Delete(anna2);
// anna2.Articles.Add(article1);
uow.Commit();
/*var comment1 = new Comment { Body = "Article1 is my first arctile. (Anna)" };
var articleRepo = new ArticleRepository(dbContext);
anna2.Comments.Add(comment1);
article1.Comments.Add(comment1);
uow.Commit();*/
}
}
示例2: 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);
}
示例3: CreateDepartment
public HttpResponseMessage CreateDepartment(string name, int managerId, int parentDepartmentId)
{
int departmentId;
Department department = null;
using (var uow = new UnitOfWork())
{
_departmentRepository.SetSession(uow.Session);
uow.BeginTransaction();
departmentId = 0;
department = _departmentRepository.CreateDepartment(name);
if (department != null)
{
departmentId = department.DepartmentId;
_departmentRepository.UpdateDepartmentsParentDepartment(departmentId, parentDepartmentId);
_departmentRepository.UpdateDepartmentsManager(departmentId, managerId);
uow.Session.Flush();
uow.Commit();
}
}
return new HttpResponseMessage((department == null) ? HttpStatusCode.BadRequest : HttpStatusCode.OK);
}
示例4: Run
public override void Run()
{
if (this.Owner is DTProjectNode)
{
DTProject domainObject = ((DTProjectNode) this.Owner).DomainObject;
if (domainObject != null)
{
int num = 0;
UnitOfWork work = new UnitOfWork(typeof(DTColumn));
foreach (DTDatabase database in domainObject.DTDatabases)
{
foreach (DTTable table in database.DTTables)
{
table.MapXMLElementName = "{0}:" + table.MapXMLElementName;
table.NamespacePrefix = "{0}";
table.NamespaceUri = "{0}";
work.RegisterDirty(table);
num++;
foreach (DTColumn column in table.DTColumns)
{
column.MapXMLElementName = "{0}:" + column.MapXMLElementName;
column.NamespacePrefix = "{0}";
column.NamespaceUri = "{0}";
work.RegisterDirty(column);
num++;
}
}
}
work.Commit();
MessageHelper.ShowInfo("批处理修改了'{0}'项", num.ToString());
}
}
}
示例5: CreateNodes
private static void CreateNodes()
{
using (var unitOfWork = new UnitOfWork())
{
var repository = new NodeRepository(unitOfWork);
for (int i = 0; i < NumberOfNodes; i++)
{
var node = new Node("Node " + (i + 1));
repository.Save(node);
}
unitOfWork.Commit();
}
using (var unitOfWork = new UnitOfWork())
{
var repository = new MongoNodeRepository(unitOfWork);
for (int i = 0; i < NumberOfNodes; i++)
{
var node = new MongoNode("Node " + (i + 1));
repository.Save(node);
}
unitOfWork.Commit();
}
}
示例6: BailAgreementReject
public ActionResult BailAgreementReject(long id)
{
ICollection<ValidationResult> error = new List<ValidationResult>();
BailAgreement bailAgreement = null;
try
{
using (var unitOfWork = new UnitOfWork(new BankModuleFactory()))
{
var Service = new BailAgreementService(unitOfWork);
bailAgreement = Service.Get(sr => sr.Id == id).First();
Service.RejectAgreement(bailAgreement);
error = unitOfWork.Commit();
}
if (error.Any())
{
ModelState.AddModelError(string.Empty, error.First().ErrorMessage);
return View("BailAgreementDetails", bailAgreement);
}
}
catch (Exception ex)
{
ModelState.AddModelError(string.Empty, ex.Message);
return View("BailAgreementDetails", bailAgreement);
}
return RedirectToAction("AgreementList");
}
示例7: Approve
public ActionResult Approve(long id)
{
ICollection<ValidationResult> error = new List<ValidationResult>();
LoanApplication loanApplication = null;
try
{
using (var unitOfWork = new UnitOfWork(new BankModuleFactory()))
{
var Service = new LoanApplicationService(unitOfWork);
loanApplication = Service.Get(sr => sr.Id == id).First();
Service.ApproveApplication(loanApplication);
error = unitOfWork.Commit();
}
if (error.Any())
{
ModelState.AddModelError(string.Empty, error.First().ErrorMessage);
return View("DetailsForConfirmation", loanApplication);
}
}
catch (Exception ex)
{
ModelState.AddModelError(string.Empty, ex.Message);
return View("DetailsForConfirmation", loanApplication);
}
return RedirectToAction("ForConfirmationList");
}
示例8: Approve
public ActionResult Approve(long id)
{
ICollection<ValidationResult> error = new List<ValidationResult>();
CommitteeResolution committeeResolution;
try
{
using (var unitOfWork = new UnitOfWork(new BankModuleFactory()))
{
var Service = new CommitteeResolutionService(unitOfWork);
committeeResolution = Service.Get(sr => sr.LoanApplicationId == id).First();
committeeResolution.UserId = Authentication.User.Id;
Service.ApproveResolution(committeeResolution);
error = unitOfWork.Commit();
}
if (error.Any())
{
ModelState.AddModelError(string.Empty, error.First().ErrorMessage);
return View();
}
}
catch (Exception ex)
{
ModelState.AddModelError(string.Empty, ex.Message);
return View();
}
return RedirectToAction("LoanApplicationList");
}
示例9: Main
private const string ConnectionString = "server=localhost;user id=root;persistsecurityinfo=True;database=supervkappdb"; //
#endregion Fields
#region Methods
static void Main(string[] args)
{
var nhibernatehelper = new NHibernateHelper(ConnectionString);
var unitofwork = new UnitOfWork(nhibernatehelper.SessionFactory);
//попробуем чонить добавить в бд
var user = new UserDomain
{
//Id = "egorveidt", какого черта я сделал интовый айдишник, фаак !!! переделать
FirstName = "Егор",
LastName = "Пичугов",
Age = 21,
Male = true
};
var post = new PostDomain
{
Date = new DateTime(2016, 01, 07),
Text = "test text exst",
};
post.AddSnapshot(new PostSnapshotDomain()
{
CountComments = 1,
CountLikes = 10,
CountReposts = 2,
Date = new DateTime(2016, 01, 07)
});
user.AddPost(post);
var userRepository = new Repository<UserDomain>(unitofwork.Session);
userRepository.SaveOrUpdate(user);
unitofwork.Commit();
}
示例10: Run
public override void Run()
{
UnitOfWork work = new UnitOfWork(typeof(DTColumn));
DTProject project = new DTProject();
project.Name = "新XML数据交换项目";
work.RegisterNew(project);
work.Commit();
((TaskTreeNode) this.Owner).AddSingleNode<DTProject, DTProjectNode>(project);
}
示例11: should_not_call_save_on_second_commit
public void should_not_call_save_on_second_commit()
{
var mocks = new MockRepository();
var eventStore = mocks.DynamicMock<IEventStore>();
var aggregate = new MockAggregate();
Expect.Call(() => eventStore.Save(aggregate));
mocks.ReplayAll();
var unitOfWork = new UnitOfWork(eventStore);
unitOfWork.Register(aggregate);
unitOfWork.Commit();
unitOfWork.Commit();
mocks.VerifyAll();
}
示例12: Commit_SavesChanges
public void Commit_SavesChanges()
{
TestingContext context = Substitute.For<TestingContext>();
UnitOfWork unitOfWork = new UnitOfWork(context);
unitOfWork.Commit();
context.Received().SaveChanges();
}
示例13: LogPost
public void LogPost(Log log)
{
using (var unitOfWork = new UnitOfWork())
{
var repository = new Repository(unitOfWork.Session);
repository.Add(log);
unitOfWork.Commit();
}
}
示例14: DaylyUpdate
public ActionResult DaylyUpdate(PayoutDatePost model)
{
using (var unitOfWork = new UnitOfWork(new BankModuleFactory()))
{
var PayoutService = new PayoutService(unitOfWork);
PayoutService.DaylyCreditUpdate(model.currentTime);
unitOfWork.Commit();
}
return RedirectToAction("Index");
}
示例15: DeleteUser
public ActionResult DeleteUser(int id, bool deleted)
{
using (var unitOfWork = new UnitOfWork(new AuthorizationModuleFactory()))
{
var userService = new UserService(unitOfWork);
userService.MarkDeleted(id, deleted);
unitOfWork.Commit();
}
return RedirectToLocal(Request.UrlReferrer.ToString(), "Users", "Administration");
}