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


C# GenericRepository.SaveChanges方法代码示例

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


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

示例1: Post

        public IHttpActionResult Post(HomeworkRequestModel model)
        {
            if (model == null)
            {
                return this.BadRequest();
            }

            var db = new StudentSystemDbContext();
            var homeworsRepo = new GenericRepository<Homework>(db);
            var coursesRepo = new GenericRepository<Course>(db);
            var studentsRepo = new GenericRepository<Student>(db);
            Course defaultCourse = coursesRepo.All().ToList().FirstOrDefault();
            Student defaultStudent = studentsRepo.All().ToList().FirstOrDefault();
            var homeworkToAdd = new Homework
            {
                FileUrl = model.FileUrl,
                TimeSent = new DateTime(model.TimeSentTicks),
                Course = defaultCourse,
                CourseId = defaultCourse.Id,
                Student = defaultStudent,
                StudentIdentification = defaultStudent.StudentIdentification
            };

            homeworsRepo.Add(homeworkToAdd);
            homeworsRepo.SaveChanges();
            return this.Ok();
        }
开发者ID:vassildinev,项目名称:Web-Services,代码行数:27,代码来源:HomeworksController.cs

示例2: Post

        public IHttpActionResult Post(TestRequestModel model)
        {
            if (model == null)
            {
                return this.BadRequest();
            }

            var db = new StudentSystemDbContext();
            var testsRepo = new GenericRepository<Test>(db);
            var coursesRepo = new GenericRepository<Course>(db);
            List<Course> allCourses = coursesRepo.All().ToList();
            var testCourse = new Course
            {
                Name = model.Course.Name,
                Description = model.Course.Description
            };

            var testToAdd = new Test
            {
                Course = testCourse
            };

            testsRepo.Add(testToAdd);
            testsRepo.SaveChanges();
            return this.Ok();
        }
开发者ID:vassildinev,项目名称:Web-Services,代码行数:26,代码来源:TestsController.cs

示例3: AddNews_Should_Throw_Exception_If_Data_Is_Invalid

        public void AddNews_Should_Throw_Exception_If_Data_Is_Invalid()
        {
            var repository = new GenericRepository<News>(new NewsContext());
            var news = new News
            {
                Title = "shor",
                Content = "Sample Content",
                PublishDate = DateTime.Now
            };

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

示例4: AddMovieWhenMovieIsInvalidShouldThrowException

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

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

            //Asssert -> expect and exception
        }
开发者ID:Aleksandyr,项目名称:Software-University,代码行数:17,代码来源:RepositoeisTest.cs

示例5: Post

        public IHttpActionResult Post(CourseRequestModel model)
        {
            if (model == null)
            {
                return this.BadRequest();
            }

            var db = new StudentSystemDbContext();
            var coursesRepo = new GenericRepository<Course>(db);
            var courseToAdd = new Course
            {
                Name = model.Name,
                Description = model.Description
            };

            coursesRepo.Add(courseToAdd);
            coursesRepo.SaveChanges();
            return this.Ok();
        }
开发者ID:vassildinev,项目名称:Web-Services,代码行数:19,代码来源:CoursesController.cs

示例6: Post

        public IHttpActionResult Post(StudentRequestModel model)
        {
            if (model == null)
            {
                return this.BadRequest();
            }

            var db = new StudentSystemDbContext();
            var studentsRepo = new GenericRepository<Student>(db);
            var studentToAdd = new Student
            {
                FirstName = model.FirstName,
                LastName = model.LastName,
                Level = model.Level
            };

            studentsRepo.Add(studentToAdd);
            studentsRepo.SaveChanges();
            return this.Ok();
        }
开发者ID:vassildinev,项目名称:Web-Services,代码行数:20,代码来源:StudentsController.cs

示例7: AddNews_Should_Successfully_Add_Specified_News_To_The_Repository

        public void AddNews_Should_Successfully_Add_Specified_News_To_The_Repository()
        {
            var repository = new GenericRepository<News>(new NewsContext());
            var news = new News
            {
                Title = "Sample Title",
                Content = "Sample Content",
                PublishDate = DateTime.Now
            };

            repository.Add(news);
            repository.SaveChanges();

            var newsFromDb = repository.Find(news.Id);

            Assert.IsNotNull(newsFromDb);
            Assert.AreEqual(news.Content, newsFromDb.Content);
            Assert.AreEqual(news.Title, newsFromDb.Title);
            Assert.AreEqual(news.PublishDate, newsFromDb.PublishDate);
            Assert.IsTrue(newsFromDb.Id != 0);
        }
开发者ID:OmniPot,项目名称:SoftUni-Level-3-Backend,代码行数:21,代码来源:RepositoryTests.cs

示例8: AddMovieWhenMovieIsAddedToDbShouldReturnMovie

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

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

            //Assert -> validate the results
            var movieFromDb = repo.GetById(movie.Id);

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

示例9: ExportCountriesFromMSSqlToMySql

 private static void ExportCountriesFromMSSqlToMySql(GenericRepository<Country> sqlCountriesRepo, GenericRepository<Country> mySqlCountriesRepo)
 {
     var countriesFromMSsql = sqlCountriesRepo.GetAll().ToList();
     foreach (var countryFromMSsql in countriesFromMSsql.ToList())
     {
         var country = new Country()
         {
             Name = countryFromMSsql.Name
         };
         mySqlCountriesRepo.Add(country);
         mySqlCountriesRepo.SaveChanges();
     }
 }
开发者ID:TeamCurrant,项目名称:GirlsAgency,代码行数:13,代码来源:CommandEngine.cs

示例10: ExportCitiesFromMSSqlToMySQL

 private static void ExportCitiesFromMSSqlToMySQL(GenericRepository<City> sqlCitiesRepo, GenericRepository<City> mySqlCitiesRepo)
 {
     var mysqlCountries = new GenericRepository<Country>(new GirlAgencyMySql.Data.MySql());
     var citiesFromMSsql = sqlCitiesRepo.GetAll().ToList();
     foreach (var cityFromMSsql in citiesFromMSsql.ToList())
     {
         var city = new City()
         {
             Name = cityFromMSsql.Name,
             CountryId = mysqlCountries.
                 GetAll()
                 .FirstOrDefault(n => n.CountryId == cityFromMSsql.CountryId).CountryId
         };
         mySqlCitiesRepo.Add(city);
         mySqlCitiesRepo.SaveChanges();
     }
 }
开发者ID:TeamCurrant,项目名称:GirlsAgency,代码行数:17,代码来源:CommandEngine.cs

示例11: 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

示例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

示例13: ListAllMovieShouldReturnAllMovies

        public void ListAllMovieShouldReturnAllMovies()
        {
            var repo = new GenericRepository<Movie>(new MoviesGalleryContext());
            var fakeMovies = new List<Movie>()
            {
                new Movie()
                {
                    Id = 1,
                    Length = 1,
                    Ration = 1
                },
                new Movie()
                {
                    Id = 2,
                    Length = 2,
                    Ration = 2
                },
                new Movie()
                {
                    Id = 3,
                    Length = 3,
                    Ration = 3
                },
            };

            foreach (var fakeMovie in fakeMovies)
            {
                repo.Add(fakeMovie);
                repo.SaveChanges();
            }

            var fakeMovieLengths = fakeMovies.Select(m => m.Length).ToList();
            var movieDbLengths = repo.All().Select(m => m.Length).ToList();

            CollectionAssert.AreEqual(fakeMovieLengths, movieDbLengths);
        }
开发者ID:Aleksandyr,项目名称:Software-University,代码行数:36,代码来源:RepositoeisTest.cs

示例14: ImportOrdersToDatabase

        private static void ImportOrdersToDatabase(IEnumerable<Order> orders)
        {
            var sqlRepo = new GenericRepository<Order>(new GirlsAgencyContext());
            var girlRepo = new GenericRepository<Girl>(new GirlsAgencyContext());
            var ctx = new GirlsAgencyContext();
            foreach (var order in orders)
            {
                sqlRepo.Add(order);
                //ctx.Customers.
            }

            sqlRepo.SaveChanges();
        }
开发者ID:TeamCurrant,项目名称:GirlsAgency,代码行数:13,代码来源:XML.cs

示例15: ExportGirlsFromMSSqlToMySql

 private static void ExportGirlsFromMSSqlToMySql(GenericRepository<Girl> sqlGirlsRepo, GenericRepository<Girl> mySqlGirlsRepo)
 {
     var girlsFromMSsql = sqlGirlsRepo.GetAll().ToList();
     foreach (var girlFromMSsql in girlsFromMSsql.ToList())
     {
         var girl = new Girl()
         {
             FirstName = girlFromMSsql.FirstName,
             LastName = girlFromMSsql.LastName,
             Age = girlFromMSsql.Age,
             BreastSizeId = girlFromMSsql.BreastSizeId,
             HairColorId = girlFromMSsql.HairColorId,
             CityId = girlFromMSsql.CityId,
             PricePerHour = girlFromMSsql.PricePerHour,
             Features = girlFromMSsql.Features,
             CountyId = girlFromMSsql.CountyId,
             // City = girlFromMSsql.City,
             // Country = girlFromMSsql.Country
         };
         mySqlGirlsRepo.Add(girl);
         mySqlGirlsRepo.SaveChanges();
     }
 }
开发者ID:TeamCurrant,项目名称:GirlsAgency,代码行数:23,代码来源:CommandEngine.cs


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