Exemple #1
0
        public static async Task<IEnumerable<BookModel>> PopulateFullBookInfo(IEnumerable<Book> source)
        {
            if (source == null || !source.Any()) return null;
            var result = new List<BookModel>();
            using (var authorRepo = new AuthorRepository())
            {
                using (var categoryRepo = new BookCategoryRepository())
                {
                    foreach (var book in source)
                    {
                        var model = new BookModel();
                        model.InjectFrom(book);
                        var author = await authorRepo.GetById(book.AuthorId);
                        var coAuthor = book.CoAuthorId != null && book.CoAuthorId > 0
                            ? await authorRepo.GetById(Convert.ToInt32(book.CoAuthorId)) : null;
                        var category = await categoryRepo.GetById(book.BookCategoryId);

                        if (author != null)
                            model.AuthorName = string.Format("{0} {1}", author.FirstName, author.LastName);
                        if (coAuthor != null)
                            model.CoAuthorName = string.Format("{0} {1}", coAuthor.FirstName, coAuthor.LastName);
                        if (category != null)
                            model.CategoryText = category.Name;

                        result.Add(model);
                    }

                    return result;
                }
            }
        }
Exemple #2
0
        public static async Task<BookModel> PopulateFullBookInfo(Book book)
        {
            if (book == null) return null;
            using (var authorRepo = new AuthorRepository())
            {
                using (var categoryRepo = new BookCategoryRepository())
                {
                    var model = new BookModel();
                    model.InjectFrom(book);
                    var author = await authorRepo.GetById(book.AuthorId);
                    var coAuthor = book.CoAuthorId != null && book.CoAuthorId > 0
                        ? await authorRepo.GetById(Convert.ToInt32(book.CoAuthorId)) : null;
                    var category = await categoryRepo.GetById(book.BookCategoryId);

                    if (author != null)
                        model.AuthorName = string.Format("{0} {1}", author.FirstName, author.LastName);
                    if (coAuthor != null)
                        model.CoAuthorName = string.Format("{0} {1}", coAuthor.FirstName, coAuthor.LastName);
                    if (category != null)
                        model.CategoryText = category.Name;

                    return model;
                }
            }
        } 
 public BookCategoryController()
 {
     _repository = new BookCategoryRepository();
 }