Ejemplo n.º 1
0
        public async Task <IActionResult> Initialize(Guid id)
        {
            BookShelfBook book = await this.initializeTransactionService.GetBookShelfBookById(id);

            User initiator = await this.initializeTransactionService.GetUserById(this.HttpContext.User.GetId() !.Value);

            User recipient = await this.initializeTransactionService.GetUserById(book.BookShelf.UserId);

            if (initiator.Id == recipient.Id)
            {
                return(this.BadRequest());
            }

            var transaction = new Transaction
            {
                Id             = Guid.NewGuid(),
                Initiator      = initiator,
                Recipient      = recipient,
                Status         = Transaction.Statuses.Initialized,
                RecipientBooks = new List <BookShelfBook> {
                    book
                }
            };

            await this.dbContext.AddAsync(transaction);

            this.dbContext.SaveChanges();

            return(this.RedirectToAction(nameof(Index), new
            {
                id = transaction.Id,
            }));
        }
Ejemplo n.º 2
0
        public async Task <BookShelfBook> GetBookShelfBookById(Guid id)
        {
            BookShelfBook bookshelf = await this.applicationDbContext.BookShelfBooks
                                      .Include(bsb => bsb.BookShelf)
                                      .ThenInclude(bs => bs.User)
                                      .Include(bsb => bsb.Book)
                                      .FirstOrDefaultAsync(bsb => bsb.Id == id);

            return(bookshelf);
        }
Ejemplo n.º 3
0
        public async Task <bool> RemoveBook(Guid Id)
        {
            BookShelfBook bok = this.applicationDbContext.BookShelfBooks.FirstOrDefault(b => b.BookId == Id);

            bok.IsRemoved = true;

            await this.applicationDbContext.SaveChangesAsync();

            return(true);
        }