Esempio n. 1
0
 public IActionResult SupplementEdit(Supplement supplement)
 {
     if (ModelState.IsValid)
     {
         _supplementService.Update(supplement);
         TempData.Add("message", "Supplement successfully updated ");
     }
     return(RedirectToAction("Supplement"));
 }
Esempio n. 2
0
        public async Task <IActionResult> UpdateSupplement([FromBody] SupplementsRequest request)
        {
            if (request == null)
            {
                return(NotFound());
            }
            var supplement = _mapper.Map <Supplement>(request);
            var result     = await _supplementService.Update(supplement);

            if (result == null)
            {
                return(NotFound());
            }
            return(Ok(supplement));
        }
Esempio n. 3
0
        public IActionResult Complete(ShippingDetail shippingDetail)
        {
            var cart = _cartSessionService.GetCart();

            shippingDetail.AccountId = _userManager.GetUserId(HttpContext.User);
            shippingDetail.Time      = DateTime.Today;
            _shippingDetailService.Add(shippingDetail);

            Order order = new Order()
            {
                AccountId        = _userManager.GetUserId(HttpContext.User),
                ShippingDetailId = shippingDetail.ID,
                Total            = cart.Total,
            };

            _orderService.Add(order);
            foreach (var item in cart.CartLines)
            {
                if (item.Supplement.UnitInStock > item.Quantity)
                {
                    item.Supplement.UnitInStock = (item.Supplement.UnitInStock - item.Quantity);
                    _supplementService.Update(item.Supplement);



                    OrderLine orderLine = new OrderLine();
                    orderLine.OrderID      = order.ID;
                    orderLine.Price        = item.Supplement.Price;
                    orderLine.SupplementID = item.Supplement.ID;
                    orderLine.Quantity     = item.Quantity;
                    orderLine.AccountId    = _userManager.GetUserId(HttpContext.User);
                    orderLine.Time         = DateTime.Today;
                    _orderLineService.Add(orderLine);
                }
            }
            cart.CartLines.Clear();
            TempData.Add("message", "Your products successfully completed");



            return(RedirectToAction("Details"));
        }