Пример #1
0
        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));
        }
Пример #2
0
        public ActionResult Edit(int id)
        {
            ShopOrderDTO shOrder     = shOrderService.GetShopOrder(id);
            var          mapper      = new MapperConfiguration(cfg => cfg.CreateMap <ShopOrderDTO, ShOrderViewModel>()).CreateMapper();
            var          productView = mapper.Map <ShOrderViewModel>(shOrder);

            return(View(productView));
        }
Пример #3
0
        public void UpdateShOrder(ShopOrderDTO shopOrderDTO)
        {
            ShopOrder shopOrder = Database.ShopOrders.Get(shopOrderDTO.ShopOrderId);

            if (shopOrder == null)
            {
                throw new ValidationException("Заказ магазина не найден", "");
            }

            // shopOrder.ProductId = shopOrderDTO.ProductId;
            shopOrder.ProductQuantity = shopOrderDTO.ProductQuantity;
            shopOrder.ShopAddress     = shopOrderDTO.ShopAddress;
            shopOrder.ShExpDate       = shopOrderDTO.ShExpDate;

            Database.ShopOrders.Update(shopOrder);
            Database.Save();
        }
Пример #4
0
 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));
 }
Пример #5
0
        public void AddShOrder(ShopOrderDTO shopOrderDTO)
        {
            Product product = Database.Products.Get(shopOrderDTO.ProductId);

            if (product == null)
            {
                throw new ValidationException("Товар не найден", "");
            }

            ShopOrder order = new ShopOrder
            {
                ShOrderDate     = DateTime.Now,
                ShopAddress     = shopOrderDTO.ShopAddress,
                ProductId       = product.ProductId,
                ProductQuantity = shopOrderDTO.ProductQuantity,
                ShExpDate       = shopOrderDTO.ShExpDate
            };

            Database.ShopOrders.Create(order);
            Database.Save();
        }