コード例 #1
0
ファイル: AdminController.cs プロジェクト: fardiis/onlineshop
        public IActionResult EditSlider(int id)
        {
            Slider slider = _admin.GetSlider(id);

            AdminSliderViewModel viewModel = new AdminSliderViewModel()
            {
                Desc      = slider.Desc,
                ImgName   = slider.Img,
                NotShow   = slider.NotShow,
                OrderShow = slider.OrderShow,
                Title     = slider.Title
            };

            return(View(viewModel));
        }
コード例 #2
0
ファイル: AdminController.cs プロジェクト: fardiis/onlineshop
        public IActionResult AddSlider(AdminSliderViewModel viewModel)
        {
            if (ModelState.IsValid)
            {
                if (viewModel.Img != null)
                {
                    if (Path.GetExtension(viewModel.Img.FileName) != ".jpg")
                    {
                        ModelState.AddModelError("Img", "فایل با پسوند jpg بارگزاری شود");
                    }
                    else
                    {
                        string filePath = "";
                        viewModel.ImgName = CodeGenerators.FileCode() + Path.GetExtension(viewModel.Img.FileName);
                        filePath          = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot/images/sliders/", viewModel.ImgName);

                        using (var stream = new FileStream(filePath, FileMode.Create))
                        {
                            viewModel.Img.CopyTo(stream);
                        }

                        Slider slider = new Slider()
                        {
                            Img       = viewModel.ImgName,
                            Title     = viewModel.Title,
                            Desc      = viewModel.Desc,
                            NotShow   = viewModel.NotShow,
                            OrderShow = viewModel.OrderShow
                        };

                        _admin.AddSlider(slider);

                        return(RedirectToAction(nameof(ShowSliders)));
                    }
                }
                else
                {
                    ModelState.AddModelError("Img", "فایل با پسوند jpg بارگزاری شود");
                }
            }

            return(View(viewModel));
        }
コード例 #3
0
ファイル: AdminController.cs プロジェクト: fardiis/onlineshop
        public IActionResult EditSlider(AdminSliderViewModel viewModel, int id)
        {
            if (ModelState.IsValid)
            {
                Slider slider = _admin.GetSlider(id);

                string sliderImg = slider.Img;

                if (viewModel.Img != null)
                {
                    if (Path.GetExtension(viewModel.Img.FileName) != ".jpg")
                    {
                        ModelState.AddModelError("Img", "فایل با پسوند jpg بارگزاری شود");
                    }
                    else
                    {
                        string filePath = "";
                        viewModel.ImgName = CodeGenerators.FileCode() + Path.GetExtension(viewModel.Img.FileName);
                        filePath          = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot/images/sliders/", viewModel.ImgName);

                        using (var stream = new FileStream(filePath, FileMode.Create))
                        {
                            viewModel.Img.CopyTo(stream);
                        }

                        sliderImg = viewModel.ImgName;
                    }
                }

                _admin.UpdateSlider(id, viewModel.Title, sliderImg, viewModel.Desc, viewModel.NotShow, viewModel.OrderShow);

                return(RedirectToAction(nameof(ShowSliders)));
            }

            return(View(viewModel));
        }