Example #1
0
        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);
        }
Example #2
0
        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());
            }
        }
Example #3
0
        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());
            }
        }
Example #4
0
 public async Task <UserFavourites> GetUserFav(BookAndUserIds bookAndUser)
 {
     return(await this.context.UserFavourites
            .Where(uf => uf.IdUser == bookAndUser.idUser && uf.IdBook == bookAndUser.idBook)
            .FirstOrDefaultAsync());
 }
Example #5
0
 public Task <bool> BorrowBook(BookAndUserIds bookAndUser)
 {
     return(this.BorrowRepo.BorrowBook(bookAndUser));
 }
Example #6
0
 public Task <int> RemoveBookToUserFavourites(BookAndUserIds bookAndUser)
 {
     return(this.UserFavRepo.RemoveBookFromUserFavourites(bookAndUser));
 }
Example #7
0
 public Task <int> AddBookToUserFavourites(BookAndUserIds bookAndUser)
 {
     return(this.UserFavRepo.addBookToUserFavourites(bookAndUser));
 }