public async Task <bool> BorrowBook(BookAndUserIds bookAndUser) { var id = await this.getMaxId() + 1; var date = DateTime.Now; var newLoan = new Loans(id, date, bookAndUser.idUser, bookAndUser.idBook); context.Loans.Add(newLoan); var result = await context.SaveChangesAsync(); return(result == 1 ? true : false); }
public async Task <int> RemoveBookFromUserFavourites(BookAndUserIds bookAndUser) { bool isInserted = await this.VerifyIfBookIsAlreadyInFavourites(bookAndUser.idBook, bookAndUser.idUser); if (isInserted == true) { var usFavToRemove = await this.GetUserFav(bookAndUser); context.Remove(usFavToRemove); return(await this.context.SaveChangesAsync()); } else { return(await this.context.SaveChangesAsync()); } }
public async Task <int> addBookToUserFavourites(BookAndUserIds bookAndUser) { bool alreadyInserted = await this.VerifyIfBookIsAlreadyInFavourites(bookAndUser.idBook, bookAndUser.idUser); if (alreadyInserted == false) { var maxId = await this.getMaxId() + 1; this.context.UserFavourites.Add(new UserFavourites(maxId, bookAndUser.idBook, bookAndUser.idUser)); return(await this.context.SaveChangesAsync()); } else { return(await this.context.SaveChangesAsync()); } }
public async Task <UserFavourites> GetUserFav(BookAndUserIds bookAndUser) { return(await this.context.UserFavourites .Where(uf => uf.IdUser == bookAndUser.idUser && uf.IdBook == bookAndUser.idBook) .FirstOrDefaultAsync()); }
public Task <bool> BorrowBook(BookAndUserIds bookAndUser) { return(this.BorrowRepo.BorrowBook(bookAndUser)); }
public Task <int> RemoveBookToUserFavourites(BookAndUserIds bookAndUser) { return(this.UserFavRepo.RemoveBookFromUserFavourites(bookAndUser)); }
public Task <int> AddBookToUserFavourites(BookAndUserIds bookAndUser) { return(this.UserFavRepo.addBookToUserFavourites(bookAndUser)); }