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


C# GenericRepository.Update方法代码示例

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


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

示例1: DoUpsert

        public ResponseMessageModel DoUpsert(SignageDigitalEntities db, Media model)
        {
            var repository = new GenericRepository<Media>(db);

            if (model.MediaId == EntityConstants.NULL_VALUE)
            {
                repository.Add(model);
            }
            else
            {
                repository.Update(model);
            }

            return new ResponseMessageModel
            {
                HasError = false,
                Title = ResShared.TITLE_REGISTER_SUCCESS,
                Message = ResShared.INFO_REGISTER_SAVED
            };
        }
开发者ID:stphosvsol,项目名称:SignageDigitalPortal,代码行数:20,代码来源:MediaService.cs

示例2: UpdateNews_Should_Successfully_Update_News

        public void UpdateNews_Should_Successfully_Update_News()
        {
            var repository = new GenericRepository<News>(new NewsContext());

            var newsToUpdate = repository.All().FirstOrDefault();
            if (newsToUpdate == null)
            {
                Assert.Fail("Cannot run test - no news in the repository");
            }

            var newsModel = new NewsBindingModel
            {
                Title = "Updated Sample title.",
                Content = "Updated Sample content",
                PublishDate = DateTime.Now
            };

            newsToUpdate.Title = newsModel.Title;
            newsToUpdate.Content = newsModel.Content;
            if (newsModel.PublishDate.HasValue)
            {
                newsToUpdate.PublishDate = newsModel.PublishDate.Value;
            }

            repository.Update(newsToUpdate);
            repository.SaveChanges();
        }
开发者ID:OmniPot,项目名称:SoftUni-Level-3-Backend,代码行数:27,代码来源:RepositoryTests.cs

示例3: UpdateNews_Should_Throw_Exeption_If_Object_Of_Update_Is_Invalid

        public void UpdateNews_Should_Throw_Exeption_If_Object_Of_Update_Is_Invalid()
        {
            var repository = new GenericRepository<News>(new NewsContext());

            var newsModel = new News
            {
                Title = "Update aaa",
                Content = "Update aaa",
                PublishDate = DateTime.Now
            };

            repository.Update(newsModel);
            repository.SaveChanges();
        }
开发者ID:OmniPot,项目名称:SoftUni-Level-3-Backend,代码行数:14,代码来源:RepositoryTests.cs

示例4: UpdateNews_Should_Throw_Exeption_If_Data_Is_Invalid

        public void UpdateNews_Should_Throw_Exeption_If_Data_Is_Invalid()
        {
            var repository = new GenericRepository<News>(new NewsContext());

            var newsToUpdate = repository.All().FirstOrDefault();
            if (newsToUpdate == null)
            {
                Assert.Fail("Cannot run test - no news in the repository");
            }

            var newsModel = new NewsBindingModel
            {
                Title = "Upda",
                Content = "Upda"
            };

            newsToUpdate.Title = newsModel.Title;
            newsToUpdate.Content = newsModel.Content;
            if (newsModel.PublishDate.HasValue)
            {
                newsToUpdate.PublishDate = newsModel.PublishDate.Value;
            }

            repository.Update(newsToUpdate);
            repository.SaveChanges();
        }
开发者ID:OmniPot,项目名称:SoftUni-Level-3-Backend,代码行数:26,代码来源:RepositoryTests.cs

示例5: Update_Valid_Object_Must_Update

        public void Update_Valid_Object_Must_Update()
        {
            //
            // Arrange
            //
            var mockModel = new Mock<IModel>();
            var mockDbSet = new Mock<DbSet<IModel>>();
            mockDbSet.Setup(x => x.Find(It.IsAny<object[]>())).Returns<object[]>(x =>
            {
                return mockModel.Object;
            });

            var mockContext = new Mock<EFDbContext>();
            mockContext.Setup(x => x.Set<IModel>()).Returns(mockDbSet.Object);
            mockContext.Setup(x => x.ChangeState(It.IsAny<object>(), It.IsAny<RecordState>())).Callback<object, RecordState>((obj, state) =>
            {
                return;
            });

            var repository = new GenericRepository<IModel>(mockContext.Object);
            //
            // Act
            //
            repository.Update(mockModel.Object);
            //
            // Assert
            //
            mockContext.Verify(x => x.ChangeState(It.IsAny<object>(), It.IsAny<RecordState>()), Times.Once);
        }
开发者ID:Cheranga,项目名称:DAL,代码行数:29,代码来源:GenericRepositoryTest.cs

示例6: Update_NULL_Object_Must_NOT_Update

        public void Update_NULL_Object_Must_NOT_Update()
        {
            //
            // Arrange
            //
            var mockDbSet = new Mock<DbSet<IModel>>();

            var mockContext = new Mock<EFDbContext>();
            mockContext.Setup(x => x.Set<IModel>()).Returns(mockDbSet.Object);

            var repository = new GenericRepository<IModel>(mockContext.Object);
            //
            // Act
            //
            repository.Update(null);
            //
            // Assert
            //
            mockContext.Verify(x => x.ChangeState(It.IsAny<object>(), It.IsAny<RecordState>()), Times.Never);
        }
开发者ID:Cheranga,项目名称:DAL,代码行数:20,代码来源:GenericRepositoryTest.cs

示例7: InsertOrUpdateArticleAndTraces

        private async Task InsertOrUpdateArticleAndTraces(ArticleModel article, IDataService dataService)
        {
            try
            {
                using (var unitOfWork = new UnitOfWork(false))
                {
                    article.PrepareForSave();

                    var addimages = new List<ImageModel>();
                    var updateimages = new List<ImageModel>();
                    //article

                    var addgalleries = new List<GalleryModel>();
                    var updategalleries = new List<GalleryModel>();
                    var addgalleryImages = new List<ImageModel>();
                    var updategalleryImages = new List<ImageModel>();
                    var addcontents = new List<ContentModel>();
                    var updatecontents = new List<ContentModel>();


                    var articleRepo = new GenericRepository<ArticleModel, ArticleEntity>(dataService);
                    var imageRepo = new GenericRepository<ImageModel, ImageEntity>(dataService);
                    var galleryRepo = new GenericRepository<GalleryModel, GalleryEntity>(dataService);
                    var contentRepo = new GenericRepository<ContentModel, ContentEntity>(dataService);

                    if (article.LeadImage != null)
                    {
                        if (article.LeadImage.Id == 0)
                            addimages.Add(article.LeadImage);
                        else
                            updateimages.Add(article.LeadImage);
                    }
                    if (article.Content != null && article.Content.Any())
                    {
                        foreach (var contentModel in article.Content)
                        {
                            if (contentModel.Id == 0)
                                addcontents.Add(contentModel);
                            else
                                updatecontents.Add(contentModel);

                            if (contentModel.ContentType == ContentType.Gallery && contentModel.Gallery != null)
                            {
                                if (contentModel.Gallery.Id == 0)
                                    addgalleries.Add(contentModel.Gallery);
                                else
                                    updategalleries.Add(contentModel.Gallery);

                                if (contentModel.Gallery.Images != null)
                                {
                                    foreach (var imageModel in contentModel.Gallery.Images)
                                    {
                                        if (imageModel.Id == 0)
                                            addgalleryImages.Add(imageModel);
                                        else
                                            updategalleryImages.Add(imageModel);
                                    }
                                    addgalleryImages.AddRange(contentModel.Gallery.Images);
                                }
                            }
                            else if (contentModel.ContentType == ContentType.Image && contentModel.Image != null)
                            {
                                if (contentModel.Image.Id == 0)
                                    addimages.Add(contentModel.Image);
                                else
                                    updateimages.Add(article.LeadImage);
                            }
                        }
                    }

                    if (article.Themes != null)
                        await _themeRepository.SetThemesByArticle(article.Id, article.Themes.Select(t => t.Id).ToList());

                    if (article.RelatedArticles != null)
                        await SetRelatedArticlesByArticleId(article.Id, article.RelatedArticles.Select(t => t.Id).ToList(), dataService);

                    await imageRepo.AddAll(addimages);
                    await galleryRepo.AddAll(addgalleries);
                    await imageRepo.AddAll(addgalleryImages);
                    await contentRepo.AddAll(addcontents);

                    if (article.Id == 0)
                        await articleRepo.Add(article);
                    else
                        await articleRepo.Update(article);

                    await imageRepo.UpdateAll(updateimages);
                    await galleryRepo.UpdateAll(updategalleries);
                    await imageRepo.UpdateAll(updategalleryImages);
                    await contentRepo.UpdateAll(updatecontents);

                    await _themeRepository.SaveChanges();

                    await unitOfWork.Commit();
                }
            }
            catch (Exception ex)
            {
                LogHelper.Instance.Log(LogLevel.Error, this, "Article cannot be saved", ex);
            }
//.........这里部分代码省略.........
开发者ID:famoser,项目名称:OfflineMedia,代码行数:101,代码来源:AktualizeArticles(20151117+1505).cs

示例8: Can_Update_Entity

        public void Can_Update_Entity()
        {
            // Arrange
            var routesRepository = new GenericRepository<Route>(this.dataBaseContext);
            var entityToUpdate = routesRepository.GetById(1);
            entityToUpdate.Name = "Updated";

            // Act
            routesRepository.Update(entityToUpdate);

            // Assert
            Assert.AreEqual(1, routesRepository.Count);
            Assert.AreEqual("Updated", routesRepository.GetById(1).Name);
        }
开发者ID:sashaalex67,项目名称:CityTravel,代码行数:14,代码来源:GenericRepositoryTests.cs

示例9: ConfirmRegister

        public async Task<ActionResult> ConfirmRegister()
        {
            ConfirmRegisterViewModel viewModel = new ConfirmRegisterViewModel();

            try
            {
                String uid = this.Request.QueryString["uid"];

                if (uid.IsNullOrBlank())
                {
                    viewModel.Message = "User not exist";
                    return View(viewModel);
                }

                using (var db = NannyContext.Create())
                {
                    GenericRepository<Models.User> repository = new GenericRepository<Models.User>(db);
                    Guid idUser = new Guid(uid);

                    User user = repository.GetByID(idUser);

                    if (user == null)
                    {
                        viewModel.Message = "User not exist";
                    }
                    else if (user.DateConfirmEmail == null)
                    {
                        user.DateConfirmEmail = DateTime.UtcNow;

                        repository.Update(user);
                        repository.Save();

                        viewModel.IdUser = idUser.ToString();
                        viewModel.Message = "Thank you for confirming your email";
                    }
                    else if (user.DateConfirmEmail != null)
                    {
                        viewModel.Message = "User already";
                    }
                }

                return View(viewModel);
            }
            catch (DataException dex)
            {
                ModelState.AddModelError("", "Unable to save changes. Try again, and if the problem persists see your system administrator.");
            }

            return View();
        }
开发者ID:NannyWeb,项目名称:Nanny,代码行数:50,代码来源:NannyController.cs

示例10: Edit

        public async Task<ActionResult> Edit([Bind(Include = "Id, FirstName, GivenName, Password, ConfirmPassword, Email, BirthDate, Description, IdGender, Postcode, IdSuburb, AddressLine1, AddressLine2, MobilePhone, HomePhone, AgreeEmailNews")] Nanny.Models.Nanny model)
        {
            Models.Nanny nanny = null;

            try
            {
                if (!ModelState.IsValid)
                {
                    return View(model);
                }

                using (var db = NannyContext.Create())
                {
                    GenericRepository<Models.Nanny> repository = new GenericRepository<Models.Nanny>(db);

                    // nanny = repository.GetByID(model.Id);

                    //nanny.FirstName = model.FirstName != nanny.FirstName ? model.FirstName : nanny.FirstName;
                    //nanny.GivenName = model.GivenName != nanny.GivenName ? model.GivenName : nanny.GivenName;
                    //nanny.Email = model.Email != nanny.Email ? model.Email : nanny.Email;
                    //nanny.Description = model.Description != nanny.Description ? model.Description : nanny.Description;
                    //nanny.BirthDate = model.BirthDate != nanny.BirthDate ? model.BirthDate : nanny.BirthDate;

                    nanny.Postcode = model.Postcode != nanny.Postcode ? model.Postcode : nanny.Postcode;
                    nanny.IdSuburb = model.IdSuburb != nanny.IdSuburb ? model.IdSuburb : nanny.IdSuburb;
                    nanny.AddressLine1 = model.AddressLine1 != nanny.AddressLine1 ? model.AddressLine1 : nanny.AddressLine1;
                    nanny.AddressLine2 = model.AddressLine2 != nanny.AddressLine2 ? model.AddressLine2 : nanny.AddressLine2;

                    nanny.MobilePhone = model.MobilePhone != nanny.MobilePhone ? model.MobilePhone : nanny.MobilePhone;
                    nanny.HomePhone = model.HomePhone != nanny.HomePhone ? model.HomePhone : nanny.HomePhone;

                    nanny.IdGender = model.IdGender != nanny.IdGender ? model.IdGender : nanny.IdGender;

                    model.DateLastUpdated = DateTime.UtcNow;

                    repository.Update(nanny);
                    repository.Save();

                    ViewBag.Genders = new GenericRepository<Gender>(db).Get();
                    ViewBag.Suburbs = new GenericRepository<Suburb>(db).Get();
                }

                return PartialView("Basic", nanny);
            }
            catch (DataException dex)
            {
                ModelState.AddModelError("", "Unable to save changes. Try again, and if the problem persists see your system administrator.");
            }

            return View(model);
        }
开发者ID:NannyWeb,项目名称:Nanny,代码行数:51,代码来源:NannyController.cs

示例11: ConfirmRegisterPassword

        public async Task<ActionResult> ConfirmRegisterPassword([Bind(Include = "Password, IdUser")] ConfirmRegisterViewModel model)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return View(model);
                }

                using (var db = NannyContext.Create())
                {
                    GenericRepository<Models.User> repository = new GenericRepository<Models.User>(db);

                    User user = repository.GetByID(model.IdUser);
                    user.Password = model.Password;
                    repository.Update(user);
                    repository.Save();
                }

                return View();
            }
            catch (DataException dex)
            {
                ModelState.AddModelError("", "Unable to save changes. Try again, and if the problem persists see your system administrator.");
            }

            return View();
        }
开发者ID:NannyWeb,项目名称:Nanny,代码行数:28,代码来源:NannyController.cs

示例12: ModifyMovieWhenExistingItemShouldModify

        public void ModifyMovieWhenExistingItemShouldModify()
        {
            //Arrange -> prepare the objects
            var repo = new GenericRepository<Movie>(new MoviesGalleryContext());
            var movie = new Movie()
            {
                Id = 1,
                Length = 10,
                Ration = 10
            };

            //Act -> perform some logic
            repo.Add(movie);
            repo.SaveChanges();

            movie.Length = 2;
            movie.Ration = 7;

            repo.Update(movie);
            repo.SaveChanges();

            var movieFromDb = repo.GetById(movie.Id);

            Assert.IsNotNull(movieFromDb);
            Assert.AreEqual(2, movieFromDb.Length);
            Assert.AreEqual(7, movieFromDb.Ration);
            Assert.IsTrue(movieFromDb.Id != 0);
        }
开发者ID:Aleksandyr,项目名称:Software-University,代码行数:28,代码来源:RepositoeisTest.cs


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