public ActionResult Create(ClOrderViewModel viewModel) { try { if (!ModelState.IsValid) { return(View(viewModel)); } var clOrder = new ClientOrderDTO { Quantity = viewModel.Quantity, ClientName = viewModel.ClientName, ClientPhone = viewModel.ClientPhone, ProductId = viewModel.ProductId, ClOrderAddress = viewModel.ClOrderAddress }; clOrderService.AddClOrder(clOrder); return(RedirectToAction("Index")); } catch (Exception e) { ModelState.AddModelError("", e.Message); } return(View(viewModel)); }
public ActionResult Edit(int id) { ClientOrderDTO clOrder = clOrderService.GetClientOrder(id); var mapper = new MapperConfiguration(cfg => cfg.CreateMap <ClientOrderDTO, ClOrderViewModel>()).CreateMapper(); var productView = mapper.Map <ClOrderViewModel>(clOrder); return(View(productView)); }
public async Task <IActionResult> AddByClient([FromBody] ClientOrderDTO clOrder) { var command = new AddClientOrder() { Order = clOrder, User = User }; await _commandDispatcher.DispatchAsync(command); return(Ok()); }
public ActionResult MakeClientOrder(int id, ClOrderViewModel order) { try { ProductDTO product = productService.GetProduct(id); ClientOrderDTO orderDTO; if (product.ProductQuantity >= order.Quantity) { orderDTO = new ClientOrderDTO { ProductId = order.ProductId, ClientName = order.ClientName, Quantity = order.Quantity, ClientPhone = order.ClientPhone, ClOrderAddress = order.ClOrderAddress, ClOrderDate = DateTime.Now, IsActive = false }; } else { orderDTO = new ClientOrderDTO { ProductId = order.ProductId, ClientName = order.ClientName, Quantity = order.Quantity, ClientPhone = order.ClientPhone, ClOrderAddress = order.ClOrderAddress, ClOrderDate = DateTime.Now, IsActive = true }; } clOrderService.AddClOrder(orderDTO); return(Content("<h2>Ваш заказ успешно оформлен</h2>")); } catch (ValidationException ex) { ModelState.AddModelError(ex.Property, ex.Message); } return(View(order)); }
public void UpdateClOrder(ClientOrderDTO clientOrderDTO) { ClientOrder clientOrder = Database.ClientOrders.Get(clientOrderDTO.ClientOrderId); if (clientOrder == null) { throw new ValidationException("Заказ магазина не найден", ""); } clientOrder.ClOrderDate = DateTime.Now; clientOrder.ClientName = clientOrderDTO.ClientName; clientOrder.ClientPhone = clientOrderDTO.ClientPhone; clientOrder.ClOrderAddress = clientOrderDTO.ClOrderAddress; clientOrder.ProductId = clientOrderDTO.ProductId; clientOrder.Quantity = clientOrderDTO.Quantity; clientOrder.IsActive = true; Database.ClientOrders.Update(clientOrder); Database.Save(); }
public void AddClOrder(ClientOrderDTO clientOrderDTO) { Product product = Database.Products.Get(clientOrderDTO.ProductId); if (product == null) { throw new ValidationException("Товар не найден", ""); } ClientOrder order = new ClientOrder { ClOrderDate = DateTime.Now, ClientName = clientOrderDTO.ClientName, ClientPhone = clientOrderDTO.ClientPhone, ClOrderAddress = clientOrderDTO.ClOrderAddress, ProductId = product.ProductId, Quantity = clientOrderDTO.Quantity, IsActive = true }; Database.ClientOrders.Create(order); Database.Save(); }