本文整理汇总了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);
}
示例2: Get
public ICollection<Student> Get()
{
var db = new StudentSystemDbContext();
var studentsRepo = new GenericRepository<Student>(db);
List<Student> students = studentsRepo.All().ToList();
return students;
}
示例3: Get
public ICollection<Homework> Get()
{
var db = new StudentSystemDbContext();
var homeworksRepo = new GenericRepository<Homework>(db);
List<Homework> homeworks = homeworksRepo.All().ToList();
return homeworks;
}
示例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();
}
示例5: Get
public ICollection<Course> Get()
{
var db = new StudentSystemDbContext();
var coursesRepo = new GenericRepository<Course>(db);
List<Course> courses = coursesRepo.All().ToList();
return courses;
}
示例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();
}
示例7: Get
public ICollection<Test> Get()
{
var db = new StudentSystemDbContext();
var testsRepo = new GenericRepository<Test>(db);
List<Test> tests = testsRepo.All().ToList();
return tests;
}
示例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();
}
示例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);
}
示例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);
}
示例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();
}
示例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();
}
示例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();
}
示例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));
}
示例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);
}