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


C# UnitOfWork.Save方法代码示例

本文整理汇总了C#中UnitOfWork.Save方法的典型用法代码示例。如果您正苦于以下问题:C# UnitOfWork.Save方法的具体用法?C# UnitOfWork.Save怎么用?C# UnitOfWork.Save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在UnitOfWork的用法示例。


在下文中一共展示了UnitOfWork.Save方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: PrefillAuthors

        private static IDictionary<string, int> PrefillAuthors(IList<boeken> books, AuthorRepository authorsRepo, UnitOfWork unitOfWork)
        {
            var allAuthorsInOldDb = books.Select(_ => _.auteurs.Trim()).Distinct().ToList();
            var newAuthors = authorsRepo.All.ToList();
            var result =  new Dictionary<string, int>();
            Console.WriteLine("Found {0} authors in old db", allAuthorsInOldDb.Count());
            foreach(var a in allAuthorsInOldDb)
            {
                var candidate = newAuthors.FirstOrDefault(_ => _.Name.ToLower() == a.ToLower());

                if (candidate == null)
                {
                    candidate = new Author()
                    {
                        State = State.Added,
                        Name = a
                    };

                    authorsRepo.InsertOrUpdate(candidate);                    
                    unitOfWork.Save();
                    newAuthors.Add(candidate);
                }
                result[a.ToLower()] = candidate.Id;                
            }
            

            return result;
        }
开发者ID:rubenvh,项目名称:ruben.books,代码行数:28,代码来源:Program.cs

示例2: Update

 public void Update(Subject model)
 {
     using (IUnitOfWork unitOfWork = new UnitOfWork())
     {
         unitOfWork.getRepository<Subject, int>().Update(model);
         unitOfWork.Save();
     }
 }
开发者ID:InsatMicrosoftClub,项目名称:IMC_webApp,代码行数:8,代码来源:SubjectService.cs

示例3: Delete

 public void Delete(Comment model)
 {
     using (IUnitOfWork unitOfWork = new UnitOfWork())
     {
         unitOfWork.getRepository<Comment, int>().Delete(model);
         unitOfWork.Save();
     }
 }
开发者ID:InsatMicrosoftClub,项目名称:IMC_webApp,代码行数:8,代码来源:CommentService.cs

示例4: addSubject

 public void addSubject(Subject model)
 {
     using (IUnitOfWork unitOfWork = new UnitOfWork())
     {
         unitOfWork.getRepository<Subject, int>().Add(model);
         unitOfWork.Save();
     }
 }
开发者ID:InsatMicrosoftClub,项目名称:IMC_webApp,代码行数:8,代码来源:SubjectService.cs

示例5: addComment

 public void addComment(Comment model)
 {
     using (IUnitOfWork unitOfWork = new UnitOfWork())
     {
         unitOfWork.getRepository<Comment, int>().Add(model);
         unitOfWork.Save();
     }
 }
开发者ID:InsatMicrosoftClub,项目名称:IMC_webApp,代码行数:8,代码来源:CommentService.cs

示例6: Save_Saves

        public void Save_Saves()
        {
            // arrange
            var uow = new UnitOfWork<FakeAnimalsDbContext>();

            // act
            var result = uow.Save();

            // assert
            Assert.That(result, Is.EqualTo(1));
        }
开发者ID:jegglestone,项目名称:Animal-Store,代码行数:11,代码来源:UnitOfWorkTests.cs

示例7: Create

 public void Create(Persona pPersona)
 {
     using (UnitOfWork uow = new UnitOfWork())
     {
         uow.PersonaRepository.Insert(pPersona);
         /*foreach (var item in pPersona.Telefonos)
         {
             uow.TelefonoRepository.Insert(item);
         }*/
         uow.Save();
     }
 }
开发者ID:ramarivera,项目名称:TP06,代码行数:12,代码来源:CRUDPersonaFacadeTest.cs

示例8: Main

        private static void Main(string[] args)
        {
            using (var context = new rubenvh_boekenEntities())
            using (var unitOfWork = new UnitOfWork())
            using (var booksRepo = new BooksRepository(unitOfWork))
            using (var categoriesRepo = new CategoryRepository(unitOfWork))
            using (var authorsRepo = new AuthorRepository(unitOfWork))
            {
                Console.WriteLine("Found {0} books.", context.boeken.Count());

                var categories = categoriesRepo.All.ToList();

                var allBooksQuery = context.boeken
                    .Include(_ => _.Readings)
                    .Include(_ => _.GenreLinks)
                    .Include(_ => _.GenreLinks.Select(g => g.Genre));
                var allBooks = allBooksQuery.ToList();

                var authorDictionary = PrefillAuthors(allBooks, authorsRepo, unitOfWork);
                var newBooks = new List<Book>(allBooks.Count);

                foreach (var book in allBooks)
                {
                    Console.WriteLine("Book {0} in {1}: {2}",
                        book.boekID,
                        book.GenreLinks.First().Genre.naam,
                        book.Readings.Any() ? book.Readings.First().datum.ToString() : "not read");

                    newBooks.Add(new Book()
                    {
                        State = State.Added,
                        FirstPublished = book.jaar.HasValue && book.jaar!=0? new DateTime(book.jaar.Value, 1, 1) : default(DateTime?),
                        Isbn = book.isbn,
                        Pages = book.blz ?? 0,
                        Title = book.titel,
                        Authors = new List<Author>() { authorsRepo.Find(authorDictionary[book.auteurs.ToLower()]) },
                        Readings = book.Readings.Select(_ => new Reading()
                                    {
                                        State = State.Added,
                                        PagesRead = book.blz ?? 0,
                                        Date = _.datum
                                    }).ToList(),
                        CategoryId = categories.Single(_ => _.Name == book.GenreLinks.First().Genre.naam).Id,
                        Tags = book.tags
                    });
                }

                newBooks.ForEach(booksRepo.InsertOrUpdateGraph);
                unitOfWork.Save();
            }
           
        }
开发者ID:rubenvh,项目名称:ruben.books,代码行数:52,代码来源:Program.cs

示例9: 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;
 }
开发者ID:tudm,项目名称:DatPhongHop,代码行数:14,代码来源:TaiKhoanDangNhapManager.cs

示例10: FillDatabase

        public void FillDatabase()
        {
            // Arrange
            var unitOfWork = new UnitOfWork();
            var context = unitOfWork.Context<SampleContext>();
            if (context.Files.Any())
            {
                throw new InvalidOperationException("Seems that thre are some data in database.");
            }
        
            (new DatabaseFill()).Fill(context);

            // Assert
            unitOfWork.Save();
        }
开发者ID:LojalnaJola,项目名称:SharpProject,代码行数:15,代码来源:CreateDatabaseTests.cs

示例11: 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); ;
            }
        }
开发者ID:ramesh533,项目名称:FlickSome,代码行数:15,代码来源:RepoTest.cs

示例12: AddController

 public int AddController(CControlerModel ip_Model)
 {
     if (ip_Model.ACTIVITY_NAME == null || ip_Model.CONTROLLER_NAME == null || ip_Model.ACTIVITY_NAME == "" || ip_Model.CONTROLLER_NAME == "")
     {
         return 200;
     }
     else
     {
         UnitOfWork uow = new UnitOfWork();
         ip_Model.State = EDataState.Added;
         var v_bo_controll = ip_Model.CopyAs<HT_CONTROLLER>();
         uow.Repository<HT_CONTROLLER>().Insert(v_bo_controll);
         uow.Save();
         return 100;
     }
 }
开发者ID:tudm,项目名称:DatPhongHop,代码行数:16,代码来源:CRoleManager.cs

示例13: ReviewAddTest

 public void ReviewAddTest()
 {
     using (IUnitOfWork unitOfWork = new UnitOfWork(new FlickSomeContext()))
     {
         var reviewRepo = unitOfWork.Repository<MovieReview>();
         reviewRepo.Insert(new MovieReview()
         {
             Movie = new Movie() { Id = 1, State = Infrastructure.Enums.ObjectState.Unchanged },
             Rating = 5,
             Review = "Review goes here...",
             ReviewedDate = DateTime.Now,
             Reviewer = new Reviewer() { Name = "TestReviewer", SiteUrl = "testreviewer.com", State = Infrastructure.Enums.ObjectState.Added},
             State = Infrastructure.Enums.ObjectState.Added,
             TagLine = "Test review tagline"
         });
         unitOfWork.Save();
     }
 }
开发者ID:ramesh533,项目名称:FlickSome,代码行数:18,代码来源:RepoTest.cs

示例14: Post

        public Tbl_Account Post(Tbl_Account account)
        {
            UnitOfWork uo = null;
            Tbl_Account accountToSave = null;
            bool editingRequired = true;
            try
            {
                uo = new UnitOfWork("CCATDBEntities");
                accountToSave = uo.AccountRepository.GetById(account.AccountNumber);
                if (accountToSave == null)
                {
                    accountToSave = new Tbl_Account();
                    accountToSave.AgencyId = (account.AgencyId == null) ? uo.Repository<Tbl_Agency>().GetAll().Where(r => r.Name == account.Tbl_Agency.Name).SingleOrDefault().AgencyId:account.AgencyId ;
                    editingRequired = false;
                }
                accountToSave.AccountNumber = account.AccountNumber;
                accountToSave.Address = account.Address;
                accountToSave.Address2 = account.Address2;
                accountToSave.City = account.City;
                accountToSave.DebtCurrentBalance = account.DebtCurrentBalance;
                accountToSave.DebtPurchaseBalance = account.DebtPurchaseBalance;
                accountToSave.FirstName = account.FirstName;
                accountToSave.HomePhone = account.HomePhone;
                accountToSave.LastFourSSN = account.LastFourSSN;
                accountToSave.LastName = account.LastName;
                accountToSave.MobilePhone = account.MobilePhone;
                accountToSave.StateId = account.StateId;
                accountToSave.WorkPhone = account.WorkPhone;
                accountToSave.Zip = account.Zip;

                if (editingRequired)
                    uo.Repository<Tbl_Account>().Update(accountToSave);
                else
                    uo.Repository<Tbl_Account>().Add(accountToSave);
                uo.Save();
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return account;
        }
开发者ID:jigshGitHub,项目名称:MSI.CCAT.VS2012,代码行数:42,代码来源:ComplianceController.cs

示例15: AssignController

        public void AssignController(Guid ip_guid_role, Guid ip_guid_controller, Guid? ip_guid_control_parent
            , string ip_str_hien_thi, string ip_str_icon, bool ip_b_hien_thi_menu)
        {
            var uow = new UnitOfWork();

            var v_phan_quyen = new HT_PHAN_QUYEN_CHUC_NANG()
            {
                ID = Guid.NewGuid(),
                ID_HT_CONTROLLER = ip_guid_controller,
                TRANG_THAI_YN = true,
                VI_TRI = 1000,
                ID_HT_USER_GROUP = ip_guid_role,
                HIEN_THI_YN = ip_b_hien_thi_menu,
                HIEN_THI_MENU = ip_str_hien_thi,
                ICON_CLASS = ip_str_icon,
                ID_CHUC_NANG_CHA = ip_guid_control_parent,
                State = EDataState.Added
            };

            uow.Repository<HT_PHAN_QUYEN_CHUC_NANG>().Insert(v_phan_quyen);
            uow.Save();
        }
开发者ID:tudm,项目名称:DatPhongHop,代码行数:22,代码来源:CRoleManager.cs


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