当前位置: 首页>>代码示例>>C#>>正文


C# UnitOfWork.Commit方法代码示例

本文整理汇总了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();*/

            }
        }
开发者ID:annmasalskaya,项目名称:SyncFramework,代码行数:51,代码来源:SfTest.cs

示例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);
        }
开发者ID:ddksaku,项目名称:pluton,代码行数:34,代码来源:ActionsLoggingAttribute.cs

示例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);
        }
开发者ID:abalkany,项目名称:nexient-net-orgchart-webapi,代码行数:26,代码来源:DepartmentController.cs

示例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());
         }
     }
 }
开发者ID:vanloc0301,项目名称:mychongchong,代码行数:33,代码来源:BatchAddNamespaceCommand.cs

示例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();
            }
        }
开发者ID:bennotti,项目名称:SqlWithMongo,代码行数:28,代码来源:Program.cs

示例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");
        }
开发者ID:vano-lukashuk,项目名称:StudentBank,代码行数:27,代码来源:AgreementController.cs

示例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");
        }
开发者ID:vano-lukashuk,项目名称:StudentBank,代码行数:27,代码来源:LoanApplicationController.cs

示例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");
        }
开发者ID:vano-lukashuk,项目名称:StudentBank,代码行数:28,代码来源:CommitteeDepartmentController.cs

示例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();
        }
开发者ID:AdrianVeidt,项目名称:supervkapp,代码行数:40,代码来源:Program.cs

示例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);
 }
开发者ID:vanloc0301,项目名称:mychongchong,代码行数:9,代码来源:AddDTProjectCommand.cs

示例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();
        }
开发者ID:RookieOne,项目名称:CodeTime-CQRS,代码行数:18,代码来源:commit.cs

示例12: Commit_SavesChanges

        public void Commit_SavesChanges()
        {
            TestingContext context = Substitute.For<TestingContext>();
            UnitOfWork unitOfWork = new UnitOfWork(context);

            unitOfWork.Commit();

            context.Received().SaveChanges();
        }
开发者ID:vmpay,项目名称:VisualStudio,代码行数:9,代码来源:UnitOfWorkTests.cs

示例13: LogPost

        public void LogPost(Log log)
        {
            using (var unitOfWork = new UnitOfWork())
            {
                var repository = new Repository(unitOfWork.Session);

                repository.Add(log);
                unitOfWork.Commit();
            }
        }
开发者ID:Vnuuk,项目名称:VStagram,代码行数:10,代码来源:LogService.cs

示例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");
 }
开发者ID:vano-lukashuk,项目名称:StudentBank,代码行数:10,代码来源:AdministrationController.cs

示例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");
 }
开发者ID:vano-lukashuk,项目名称:StudentBank,代码行数:10,代码来源:AdministrationController.cs


注:本文中的UnitOfWork.Commit方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。