public IActionResult SupplementEdit(Supplement supplement) { if (ModelState.IsValid) { _supplementService.Update(supplement); TempData.Add("message", "Supplement successfully updated "); } return(RedirectToAction("Supplement")); }
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)); }
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")); }