コード例 #1
0
ファイル: Helper.cs プロジェクト: carlitrosss6/LatamTest
        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;
                }
            }
        }
コード例 #2
0
ファイル: Helper.cs プロジェクト: carlitrosss6/LatamTest
        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;
                }
            }
        } 
コード例 #3
0
        public async Task<IEnumerable<Book>> GetByAuthor(string firstName, string lastName)
        {
            using (var authorRepo = new AuthorRepository())
            {
                var matchingAuthors = await authorRepo.GetByName(firstName, lastName);

                if (!matchingAuthors.Any()) return null;

                return
                    await
                        _context.Books.Where(
                            book => matchingAuthors.Any(a => a.AuthorId == book.AuthorId) && book.Visible).ToListAsync();
            }
        }
コード例 #4
0
 public AuthorController()
 {
     _repository = new AuthorRepository();
 }