public async Task <BookOrderedResponse> UpdateAsync(int id, BookOrdered bookOrdered)
        {
            var existingBookOrdered = await bookOrderedRepository.FindByIdAsync(id);

            if (existingBookOrdered == null)
            {
                return(new BookOrderedResponse("Book ordered not found"));
            }
            if (existingBookOrdered.BookForSaleId != bookOrdered.BookForSaleId)
            {
                return(new BookOrderedResponse("The book for sale can`t be changed in book ordered"));
            }
            if (existingBookOrdered.BookForSale.BookOrdered != null)
            {
                return(new BookOrderedResponse("Book was sold or reserved"));
            }

            existingBookOrdered.Sold = bookOrdered.Sold;

            try
            {
                bookOrderedRepository.Update(existingBookOrdered);
                await unitOfWork.CompleteAsync();

                return(new BookOrderedResponse(existingBookOrdered));
            }
            catch (Exception ex)
            {
                return(new BookOrderedResponse($"Error when updating BookOrdered: {ex.Message}"));
            }
        }
        public async Task <BookOrderedResponse> SaveAsync(BookOrdered bookOrdered)
        {
            var existingBookForSale = await bookForSaleRepository.FindByIdAsync(bookOrdered.BookForSaleId);

            if (existingBookForSale == null)
            {
                return(new BookOrderedResponse("Book for sale not found"));
            }
            if (existingBookForSale.BookOrdered != null)
            {
                return(new BookOrderedResponse("Book for sale was sold or reserved"));
            }

            try
            {
                await bookOrderedRepository.AddAsync(bookOrdered);

                await unitOfWork.CompleteAsync();

                return(new BookOrderedResponse(bookOrdered));
            }
            catch (Exception ex)
            {
                return(new BookOrderedResponse($"Error when saving the BookOrdered: {ex.Message}"));
            }
        }
 public BookOrderedResponse(bool success, string message, BookOrdered bookOrdered) : base(success, message)
 {
     BookOrdered = bookOrdered;
 }
 public BookOrderedResponse(BookOrdered bookOrdered) : this(true, string.Empty, bookOrdered)
 {
 }
 public void Update(BookOrdered bookOrdered)
 {
     context.BooksOrdered.Update(bookOrdered);
 }
 public void Remove(BookOrdered bookOrdered)
 {
     context.BooksOrdered.Remove(bookOrdered);
 }
 public async Task AddAsync(BookOrdered bookOrdered)
 {
     await context.BooksOrdered.AddAsync(bookOrdered);
 }