Esempio n. 1
0
        public async Task <int> DeleteBook(int?BookId)
        {
            int result = 0;

            if (_context != null)
            {
                var book = await _context.BookInfos.FirstOrDefaultAsync(x => x.BookId == BookId);

                if (book != null)
                {
                    _context.Remove(book);
                    result = await _context.SaveChangesAsync();
                }
                return(result);
            }
            return(result);
        }
Esempio n. 2
0
 public bool Delete(Carousel Item)
 {
     try
     {
         Carousel book = Get(Item.Id);
         if (book != null)
         {
             _context.Remove(Item);
             _context.SaveChanges();
             return(true);
         }
         return(false);
     }
     catch (Exception)
     {
         return(false);
     }
 }
Esempio n. 3
0
 public bool Delete(Order Item)
 {
     try
     {
         Order order = Get(Item.Id);
         if (order != null)
         {
             _context.Remove(Item);
             _context.SaveChanges();
             return(true);
         }
         return(false);
     }
     catch (Exception)
     {
         return(false);
     }
 }
        public async Task <OrderModel> Handle(SubmitOrderCommand request, CancellationToken cancellationToken)
        {
            var cart = await _dbContext.Carts
                       .Include(x => x.Books)
                       .SingleOrDefaultAsync(
                x => x.Id == request.CartId, cancellationToken);

            if (cart == null)
            {
                throw NotFoundError.CreateForResource(nameof(Cart), request.CartId).ToException();
            }
            var order = new Order(cart, request.PhoneNumber);
            await _dbContext.AddAsync(order, cancellationToken);

            _dbContext.Remove(cart);
            await _dbContext.SaveChangesAsync(cancellationToken);

            return(_mapper.Map <OrderModel>(order));
        }