Ejemplo n.º 1
0
        public IActionResult SetOrderDispatched(int id)
        {
            var order = _context.Find <Order>(id);

            if (order == null)
            {
                return(NoContent());
            }
            order.MarkOrderAsDispatched();
            _context.SaveChanges();
            return(Ok());
        }
Ejemplo n.º 2
0
        public void BizAction(PlaceOrderDto dto)
        {
            var bookOrders = dto.LineItems.Select(x =>
                                                  new OrderBooksDto(x.BookId, _context.Find <Book>(x.BookId), x.NumBooks));
            var user        = _context.Find <User>(dto.UserId);
            var orderStatus = Order.CreateOrderViaBizLogic(user.UserName, bookOrders);

            CombineErrors(orderStatus);
            if (orderStatus.HasErrors)
            {
                return;
            }

            _context.Add(orderStatus.Result);
            _context.SaveChanges();
            _mailService.SendMail(user, "...");
        }
Ejemplo n.º 3
0
        public Book AddPromotion(AddRemovePromotionDto dto)
        {
            var book = _context.Find <Book>(dto.BookId);

            if (book == null)
            {
                AddError("Sorry, I could not find the book you were looking for.");
                return(null);
            }
            CombineStatuses(book.AddPromotion(dto.ActualPrice, dto.PromotionalText));
            if (!IsValid)
            {
                return(null);
            }

            _context.SaveChanges();
            return(book);
        }
Ejemplo n.º 4
0
        public Book AddReviewToBook(AddReviewDto dto)
        {
            var book = _context.Find <Book>(dto.BookId);

            if (book == null)
            {
                AddError("Sorry, I could not find the book you were looking for.");
                return(null);
            }
            book.AddReview(dto.NumStars, dto.Comment, dto.VoterName, _context);
            _context.SaveChanges();
            return(book);
        }
Ejemplo n.º 5
0
 public Book UpdateBook(int id, ChangePubDateDto dto)   
 {
     //Should return error message on not found
     var book = _context.Find<Book>(id);
     if (book == null)
     {
         AddError("Sorry, I could not find the book you were looking for.");
         return null;
     }
     
     book.UpdatePublishedOn(dto.PublishedOn);        
     _context.SaveChanges();                    
     return book;                               
 }