public ActionResult Create(ShOrderViewModel viewModel) { try { if (!ModelState.IsValid) { return(View(viewModel)); } var shOrder = new ShopOrderDTO { ProductQuantity = viewModel.ProductQuantity, ShopAddress = viewModel.ShopAddress, ShExpDate = viewModel.ShExpDate, ProductId = viewModel.ProductId }; shOrderService.AddShOrder(shOrder); return(RedirectToAction("Index")); } catch (Exception e) { ModelState.AddModelError("", e.Message); } return(View(viewModel)); }
public ActionResult Delete(int id, ShOrderViewModel viewModel) { try { shOrderService.DeleteShOrder(id); return(RedirectToAction("Index")); } catch { ModelState.AddModelError("", "An error has occured. This Employee was not deleted."); } return(View(viewModel)); }
public ActionResult MakeShopOrder(int?id) { try { ProductDTO product = productService.GetProduct(id); var order = new ShOrderViewModel { ProductId = product.ProductId }; return(View(order)); } catch (ValidationException ex) { return(Content(ex.Message)); } }
public ActionResult MakeShopOrder(ShOrderViewModel order) { try { var orderDto = new ShopOrderDTO { ProductId = order.ProductId, ShopAddress = order.ShopAddress, ProductQuantity = order.ProductQuantity, ShExpDate = order.ShExpDate }; shOrderService.AddShOrder(orderDto); return(Content("<h2>Ваш заказ успешно оформлен</h2>")); } catch (ValidationException ex) { ModelState.AddModelError(ex.Property, ex.Message); } return(View(order)); }
public ActionResult Edit(int id, ShOrderViewModel viewModel) { try { if (!ModelState.IsValid) { return(View(viewModel)); } var mapper = new MapperConfiguration(cfg => cfg.CreateMap <ShOrderViewModel, ShopOrderDTO>()).CreateMapper(); var productView = mapper.Map(viewModel, shOrderService.GetShopOrder(id)); shOrderService.UpdateShOrder(productView); return(RedirectToAction("Index")); } catch (Exception e) { ModelState.AddModelError("", e.Message); } return(View(viewModel)); }
public ActionResult Create() { var newShopOrder = new ShOrderViewModel(); return(View(newShopOrder)); }