public async Task <bool> DeleteProduct([FromBody] RemoveProductFromCartViewModel model) { if (ModelState.IsValid) { Cart cart = new Cart(HttpContext); var goods = await _streinger.Goods(); var prod = (goods).First(g => g.Product.Name == model.ProductName && g.Supplier.Name == model.Supplier && g.Supplier.Address == model.AddressSupplier); cart.Remove(prod); return(true); } return(false); }
/// <summary> /// Removes the specified model. /// </summary> /// <param name="model">The model.</param> public void Remove(RemoveProductFromCartViewModel model) { var product = _productRepository.FindById(model.ProductId); if (product == null) { _eventDispatcher.RaiseEvent(new DomainNotification(MessageType, string.Format("Product was not found with this Id: {0}", model.ProductId))); return; } var cart = _cartRepository.FindSingleBySpec(new CustomerCartSpec(model.CustomerId)); if (cart == null) { _eventDispatcher.RaiseEvent(new DomainNotification(MessageType, string.Format("Cart was not found with this customer Id: {0}", model.CustomerId))); return; } cart.Remove(product); }
public IActionResult RemoveProductFromCart([FromBody] RemoveProductFromCartViewModel model) { try { if (!ModelState.IsValid) { return(BadRequest(new { IsSuccessStatusCode = false, Errors = ModelState })); } _cartService.Remove(model); if (Errors.Any()) { return(BadRequest(new { IsSuccessStatusCode = false, Errors })); } return(Ok(new { IsSuccessStatusCode = true })); } catch (Exception ex) { return(NotFound(new { IsSuccessStatusCode = false, Errors = ex.Message })); } }