Exemplo n.º 1
0
        public IActionResult Edit(int?id)
        {
            if (HttpContext.Session.GetInt32("LoginLevel") != 2)
            {
                ViewBag.checkLogin = 0;
                return(View("../Home/AddCart"));
            }
            if (id == null)
            {
                return(NotFound());
            }

            var brand = _service.GetBrand(id.Value);

            if (brand == null)
            {
                return(NotFound());
            }

            BrandEditVm BrandEdit = new BrandEditVm()
            {
                Id             = brand.ID,
                Name           = brand.Name,
                Status         = brand.Status,
                ExistPhotoPath = brand.PhotoPath,
            };
            var x = _brandService.GetList();

            ViewBag.StatusList = x.StatusList;
            return(View(BrandEdit));
        }
Exemplo n.º 2
0
        public IActionResult Edit(BrandEditVm model)
        {
            if (HttpContext.Session.GetInt32("LoginLevel") != 2)
            {
                ViewBag.checkLogin = 0;
                return(View("../Home/AddCart"));
            }
            if (ModelState.IsValid)
            {
                var brands = _service.GetAll();
                foreach (BrandDto item in brands)
                {
                    if (item.Name.ToLower().Equals(model.Name.ToLower()) && item.ID != model.Id)
                    {
                        var x = _brandService.GetList();
                        ViewBag.StatusList            = x.StatusList;
                        ViewBag.BrandEditErrorMessage = "Error!";
                        return(View(model));
                    }
                }

                BrandDto     brandDto     = _service.GetBrand(model.Id);
                SaveBrandDto saveBrandDto = _mapper.Map <BrandDto, SaveBrandDto>(brandDto);
                saveBrandDto.Name   = model.Name;
                saveBrandDto.Status = model.Status;
                //saveBrandDto.PhotoPath = model.ExistPhotoPath;

                if (model.Photo != null)
                {
                    if (model.ExistPhotoPath != null)
                    {
                        string filePath = Path.Combine(_hostingEnvironment.WebRootPath, "images", model.ExistPhotoPath);
                        System.IO.File.Delete(filePath);
                    }
                    saveBrandDto.PhotoPath = ProcessUploadedFile(model);
                }
                _service.Update(saveBrandDto);
                return(View("Detail", _service.GetBrand(saveBrandDto.ID)));
            }
            return(View());
        }