public async Task AddAsync(Author newAuthor) { var entity = Mapper.Map <Entities.Author>(newAuthor); await _context.AddAsync(entity); await _context.SaveChangesAsync(); }
public async Task AddNewBook(Book book) { book.Author = _context.Authors.FirstOrDefault(a => a.Id == book.Author.Id); await _context.AddAsync(book); await _context.SaveChangesAsync(); }
public async Task AddAsync(Book newBook) { var entity = Mapper.Map <Entities.Book>(newBook); await _context.AddAsync(entity); try { await _context.SaveChangesAsync(); } catch (DbUpdateException e) { var innerEx = (Npgsql.PostgresException)e.InnerException; if (innerEx.SqlState == "23503") { throw new MemberRelationException("Check entered value. ", innerEx.ConstraintName.Substring(0, innerEx.ConstraintName.Length - 3)); } else { throw; } } }
public async Task AddRangeAsync(IEnumerable <UserBook> userBooks) { var bookIds = userBooks.Select(u => u.BookId); var books = await _context.Book.Where(b => bookIds.Contains(b.Id)).ToListAsync(); foreach (var item in userBooks) { var book = books.Find(b => b.Id == item.BookId); if (book.AvailableCount >= item.Count) { var entity = Mapper.Map <Entities.UserBook>(item); await _context.AddAsync(entity); book.AvailableCount -= item.Count; } else { _context.Dispose(); throw new OrderedBookAvailabilityException("Books available count has been updated!"); } } await _context.SaveChangesAsync(); }
public async Task AddUserAsync(User user) { await _context.AddAsync(user); await _context.SaveChangesAsync(); }
public async Task InsertAuthor(Author autor) { await _dbContext.AddAsync(autor); await _dbContext.SaveChangesAsync(); }
public async Task AddAsync(User newUser) { var entity = Mapper.Map<Entities.User>(newUser); await _context.AddAsync(entity); await _context.SaveChangesAsync(); }
public async Task Add(Book book) { await _context.AddAsync(book); await _context.SaveChangesAsync(); }