public BookModel GetBook(long id) { BookRepository bRepo = new BookRepository(_dal); StoryRepository sRepo = new StoryRepository(_dal); Book book = bRepo.Get(id); if (book == null) throw new HttpException(404, "Ressource not found"); Story[] stories = sRepo.List().Where(s => s.bookid == id).ToArray(); List<string> storyNames = new List<string>(); foreach (Story story in stories) { storyNames.Add(story.name); } BookModel bookModel = new BookModel() { Id = book.id, Name = book.name, Number = book.number, CategoryId = book.catid, Image = book.image, Added = book.added, Stories = storyNames.ToArray() }; return bookModel; }
public long StoryCount() { StoryRepository sRepo = new StoryRepository(_dal); return sRepo.List().Count(); }