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 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)); }