Пример #1
0
        public ActionResult Edit(HttpPostedFileBase uploadImg, Employee updatedEmployee)
        {
            if (!ModelState.IsValid)
            {
                return(View(updatedEmployee));
            }

            string imageName = FileManipulation.SavePhoto(uploadImg, Server.MapPath(uploadedImagesPath));
            string oldEmpImg = FileManipulation.GetFileName(updatedEmployee.img);

            if (!string.IsNullOrEmpty(imageName))
            {
                FileManipulation.DeletePhoto(Server.MapPath(uploadedImagesPath), oldEmpImg);
                updatedEmployee.img = imageName;
            }
            else
            {
                if (oldEmpImg == placeholderImageFileName)
                {
                    updatedEmployee.img = null;
                }
                else
                {
                    updatedEmployee.img = oldEmpImg;
                }
            }

            _uow.Employees.Update(updatedEmployee);
            _uow.SaveChanges();

            return(RedirectToAction("Index"));
        }