コード例 #1
0
        public async Task <ActionResult> AddEditHookah(HookahViewModel hvm, HttpPostedFileBase uploadImage)
        {
            if (ModelState.IsValid)
            {
                //добавление изображения к товару
                string imagePath = null;
                if (uploadImage != null)
                {
                    if (!uploadImage.ContentType.StartsWith("image"))
                    {
                        ModelState.AddModelError("", "Недопустимый тип файла");
                    }
                    else
                    {
                        imagePath = "/Files/ProductImages/" + Path.GetFileName(uploadImage.FileName);
                        uploadImage.SaveAs(Server.MapPath("~" + imagePath));
                    }
                }

                //создание DTO из ViewModel
                Mapper.Initialize(cfg => cfg.CreateMap <HookahViewModel, HookahDTO>());
                HookahDTO hookahDto = Mapper.Map <HookahViewModel, HookahDTO>(hvm);
                hookahDto.Image = imagePath;

                if (hvm.ProductId == Guid.Empty) //добавление нового продукта
                {
                    await productService.AddHookah(hookahDto);

                    return(RedirectToAction("AddEditHookah"));
                }
                else //изменение существующего
                {
                    await productService.EditHookah(hookahDto);

                    return(RedirectToAction("Products"));
                }
            }
            else
            {
                return(View("AddEditHookah", hvm));
            }
        }
コード例 #2
0
        public async Task <ActionResult> EditProduct(Guid?productId)
        {
            if (productId == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            var(product, productType) = await productService.GetProductParamsAsync((Guid)productId);

            if (productType == ProductType.Hookah)
            {
                HookahDTO       hookah = (HookahDTO)product;
                HookahViewModel hvm    = new HookahViewModel()
                {
                    ProductId = hookah.ProductId, Mark = hookah.Mark, Model = hookah.Model, Country = hookah.Country, Description = hookah.Description, Price = hookah.Price, Height = hookah.Height, Image = hookah.Image
                };
                return(View("AddEditHookah", hvm));
            }
            return(RedirectToAction("Products"));
        }
コード例 #3
0
        public IActionResult Mochalkin()
        {
            var models = new List <HookahViewModel>();

            var maklaudViewModel = new HookahViewModel();

            maklaudViewModel.Name                = "Maklaud Skytech";
            maklaudViewModel.Price               = 26900;
            maklaudViewModel.Material            = "Stainless steel";
            maklaudViewModel.ManufacturerCountry = "Russia";
            maklaudViewModel.Height              = 62;
            maklaudViewModel.Url = "https://maklaud.ru/image/cache/catalog/Exlusive/Maklaud%20Skytech/Maklaud%20Skytech%20(7)-400x600.jpg";
            models.Add(maklaudViewModel);

            var vinsentViewModel = new HookahViewModel();

            vinsentViewModel.Name  = "Indroduce Vinsent Vega!";
            vinsentViewModel.Price = null;
            vinsentViewModel.Url   = "https://i.gifer.com/origin/3e/3e6bcf910e0ba9422b6e1ea79cdc6665_w200.webp";
            models.Add(vinsentViewModel);

            return(View(models));
        }
コード例 #4
0
        public ActionResult AddEditHookah()
        {
            HookahViewModel hvm = new HookahViewModel();

            return(View(hvm));
        }