示例#1
0
        public IActionResult Edit(int id)
        {
            Cloth cloth = _clothRepository.GetCloth(id);
            ClothEditViewModel employeeEditViewModel = new ClothEditViewModel
            {
                Id                = cloth.Id,
                Title             = cloth.Title,
                Price             = cloth.Price,
                Description       = cloth.Description,
                ExistingPhotoPath = cloth.PhotoPath
            };

            return(View(employeeEditViewModel));
        }
示例#2
0
        public IActionResult Edit(ClothEditViewModel model)
        {
            if (ModelState.IsValid)
            {
                Cloth cloth = _clothRepository.GetCloth(model.Id);
                cloth.Title       = model.Title;
                cloth.Price       = model.Price;
                cloth.Description = model.Description;

                if (model.Photo != null)
                {
                    if (model.ExistingPhotoPath != null)
                    {
                        string filePath = Path.Combine(hostingEnvironment.WebRootPath, "images", model.ExistingPhotoPath);
                        System.IO.File.Delete(filePath);
                    }
                    cloth.PhotoPath = ProcessUploadedFile(model);
                }
                _clothRepository.Update(cloth);
                return(RedirectToAction("index"));
            }
            return(View());
        }