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 Delete(int id, ClOrderViewModel viewModel)
 {
     try
     {
         clOrderService.DeleteClOrder(id);
         return(RedirectToAction("Index"));
     }
     catch
     {
         ModelState.AddModelError("", "An error has occured. This Employee was not deleted.");
     }
     return(View(viewModel));
 }
Exemple #3
0
        public ActionResult MakeClientOrder(int?id)
        {
            try
            {
                ProductDTO product = productService.GetProduct(id);
                var        order   = new ClOrderViewModel {
                    ProductId = product.ProductId
                };

                return(View(order));
            }
            catch (ValidationException ex)
            {
                return(Content(ex.Message));
            }
        }
Exemple #4
0
        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 ActionResult Edit(int id, ClOrderViewModel viewModel)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(View(viewModel));
                }

                var mapper      = new MapperConfiguration(cfg => cfg.CreateMap <ClOrderViewModel, ClientOrderDTO>()).CreateMapper();
                var productView = mapper.Map(viewModel, clOrderService.GetClientOrder(id));

                clOrderService.UpdateClOrder(productView);


                return(RedirectToAction("Index"));
            }
            catch (Exception e)
            {
                ModelState.AddModelError("", e.Message);
            }

            return(View(viewModel));
        }