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


C# GenericRepository.All方法代码示例

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


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

示例1: GetAllNews_Should_Return_All_News_From_The_Repository

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

            var newsCount = repository.All().Count();
            var news = repository.All();
            var actualResult = news.Count();

            Assert.AreEqual(newsCount, actualResult);
        }
开发者ID:OmniPot,项目名称:SoftUni-Level-3-Backend,代码行数:10,代码来源:RepositoryTests.cs

示例2: Get

 public ICollection<Student> Get()
 {
     var db = new StudentSystemDbContext();
     var studentsRepo = new GenericRepository<Student>(db);
     List<Student> students = studentsRepo.All().ToList();
     return students;
 }
开发者ID:vassildinev,项目名称:Web-Services,代码行数:7,代码来源:StudentsController.cs

示例3: Get

 public ICollection<Homework> Get()
 {
     var db = new StudentSystemDbContext();
     var homeworksRepo = new GenericRepository<Homework>(db);
     List<Homework> homeworks = homeworksRepo.All().ToList();
     return homeworks;
 }
开发者ID:vassildinev,项目名称:Web-Services,代码行数:7,代码来源:HomeworksController.cs

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

示例5: Get

 public ICollection<Course> Get()
 {
     var db = new StudentSystemDbContext();
     var coursesRepo = new GenericRepository<Course>(db);
     List<Course> courses = coursesRepo.All().ToList();
     return courses;
 }
开发者ID:vassildinev,项目名称:Web-Services,代码行数:7,代码来源:CoursesController.cs

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

示例7: Get

 public ICollection<Test> Get()
 {
     var db = new StudentSystemDbContext();
     var testsRepo = new GenericRepository<Test>(db);
     List<Test> tests = testsRepo.All().ToList();
     return tests;
 }
开发者ID:vassildinev,项目名称:Web-Services,代码行数:7,代码来源:TestsController.cs

示例8: GetTopUsers

        public IQueryable<UserResponseModel> GetTopUsers()
        {
            GenericRepository<User> users = new GenericRepository<User>(new TeleImotDbContext());

            return users
                .All()
                .OrderBy(u => u.Rating)
                .Take(10)
                .Select(UserResponseModel.FromUser)
                .AsQueryable();
        }
开发者ID:AndrewMitev,项目名称:Telerik-Academy,代码行数:11,代码来源:UserService.svc.cs

示例9: Post

        // POST api/Songs
        public IHttpActionResult Post([FromBody]SongServiceModel value)
        {
            var artists = new GenericRepository<Artist>(Data);

            if (!artists.All().Any(x => x.Name == value.Artist))
            {
                var newArtist = new Artist { Name = value.Artist };
                artists.Add(newArtist);
                Data.SaveChanges();
            }

            var song = new Song
            {
                Title = value.Title,
                Genre = value.Genre,
                ReleasedOn = value.ReleasedOn,
                Artist = artists.All().FirstOrDefault(x => x.Name == value.Artist),
                ArtistId = artists.All().Where(x => x.Name == value.Artist).Select(x => x.ArtistId).FirstOrDefault()
            };

            SongsRepository.Add(song);
            Data.SaveChanges();
            return this.StatusCode(HttpStatusCode.Created);
        }
开发者ID:b-slavov,项目名称:Telerik-Software-Academy,代码行数:25,代码来源:SongsController.cs

示例10: Post

        // POST api/Albums
        public IHttpActionResult Post([FromBody]AlbumServiceModel value)
        {
            var artists = new GenericRepository<Artist>(Data);
            var songs = new GenericRepository<Song>(Data);

            if (value.Artists != null)
            {
                foreach (var artist in value.Artists)
                {
                    if (!artists.All().Any(x => x.Name == artist))
                    {
                        var newArtist = new Artist { Name = artist };
                        artists.Add(newArtist);
                    }

                    Data.SaveChanges();
                }
            }

            if (value.Songs != null)
            {
                foreach (var song in value.Songs)
                {
                    if (!songs.All().Any(x => x.Title == song))
                    {
                        var newSong = new Song { Title = song };
                        songs.Add(newSong);
                    }

                    Data.SaveChanges();
                }
            }

            var album = new Album
            {
                Title = value.Title,
                Genre = value.Genre,
                ReleasedOn = value.ReleasedOn,
                Artists = artists.All().Where(x => value.Artists.Contains(x.Name)).ToList(),
                Songs = songs.All().Where(x => value.Songs.Contains(x.Title)).ToList()
            };

            AlbumsRepository.Add(album);
            Data.SaveChanges();
            return this.StatusCode(HttpStatusCode.Created);
        }
开发者ID:b-slavov,项目名称:Telerik-Software-Academy,代码行数:47,代码来源:AlbumsController.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: DeleteNews_Should_Successfully_Delete_Object_If_It_Exists

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

            var newsModel = repository.All().FirstOrDefault();
            if (newsModel == null)
            {
                Assert.Fail("Cannot perform test - Unable to delete unexisting object.");
            }

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

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

示例14: Put

        // PUT api/Songs/5
        public IHttpActionResult Put(int id, [FromBody]SongServiceModel value)
        {
            var songToUpdate = SongsRepository.All().FirstOrDefault(x => x.SongId == id);

            if (songToUpdate == null)
            {
                return this.BadRequest("No such song");
            }

            if (value.Title != null)
            {
                songToUpdate.Title = value.Title;
            }

            if (value.Genre != null)
            {
                songToUpdate.Genre = value.Genre;
            }

            if (value.ReleasedOn != null)
            {
                songToUpdate.ReleasedOn = value.ReleasedOn;
            }

            if (value.Artist != null)
            {
                var artists = new GenericRepository<Artist>(Data);

                if (!artists.All().Any(x => x.Name == value.Artist))
                {
                    var newArtist = new Artist { Name = value.Artist };
                    artists.Add(newArtist);
                    Data.SaveChanges();
                }

                songToUpdate.Artist = artists.All().FirstOrDefault(x => x.Name == value.Artist);
                songToUpdate.ArtistId =
                    artists.All().Where(x => x.Name == value.Artist).Select(x => x.ArtistId).FirstOrDefault();
            }

            Data.SaveChanges();

            return this.ResponseMessage(new HttpResponseMessage(HttpStatusCode.Accepted));
        }
开发者ID:b-slavov,项目名称:Telerik-Software-Academy,代码行数:45,代码来源:SongsController.cs

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


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