public async Task <BookListModel> Add(BookListModel bookList) { if (bookList.User == null) { bookList.User = AppEnvironment.CurrentUser; } bookList.Order = (await GetAllRaw()).Count; _context.Add(bookList); await _context.SaveChangesAsync(); return(bookList); }
public async Task <BookCategoryModel> Add(BookCategoryModel category) { category.Name = category.Name.ToUpper(); BookCategoryModel categorySameName = await GetByName(category.Name); if (categorySameName != null) { return(categorySameName); } _context.Add(category); await _context.SaveChangesAsync(); return(category); }
public async Task <AuthorModel> Add(AuthorModel author) { AuthorModel authorSameName = await GetByName(author.Name); if (authorSameName != null) { return(authorSameName); } author.Name = author.Name.ToUpper(); _context.Add(author); await _context.SaveChangesAsync(); return(author); }
public async Task <PublisherModel> Add(PublisherModel publisher) { PublisherModel publisherSameName = await GetByName(publisher.Name); if (publisherSameName != null) { return(publisherSameName); } publisher.Name = publisher.Name.ToUpper(); _context.Add(publisher); await _context.SaveChangesAsync(); return(publisher); }
public async Task <BookModel> Add(BookModel book) { if (book == null) { return(null); } if (book.Id > 0) { return(book); } try { if (book.Categories != null) { foreach (BookCategoryModel category in book.Categories) { await _category.Add(category); } } if (book.Authors != null) { foreach (AuthorModel author in book.Authors) { await _author.Add(author); } } if (book.Publisher != null) { await _publisher.Add(book.Publisher); } _context.Add(book); await _context.SaveChangesAsync(); return(book); } catch (Exception ex) { string message = ex.Message; return(null); } }