public IActionResult Edit(EmployeeEditViewModel model)
 {
     if (ModelState.IsValid)
     {
         Employee employee = _employeeRpository.GetEmployee(model.Id);
         employee.Name       = model.Name;
         employee.Email      = model.Email;
         employee.Department = model.Department;
         if (model.Photo != null)
         {
             if (model.ExistingPhotoPath != null)
             {
                 string filePath = Path.Combine(hostingEnvironment.WebRootPath, "images", model.ExistingPhotoPath);
                 System.IO.File.Delete(filePath);
             }
             employee.PhotoPath = ProcessUploadedFile(model);
         }
         _employeeRpository.Update(employee);
         return(RedirectToAction("index"));
     }
     return(View());
 }
示例#2
0
        public IActionResult Edit(EmployeeEditViewModel model)
        {
            if (ModelState.IsValid)
            {
                Employee employee = _employeeRepository.GetEmployee(model.Id);
                employee.Name       = model.Name;
                employee.Email      = model.Email;
                employee.Department = model.Department;
                if (model.Photos != null)
                {
                    if (model.ExistingPhotoPath != null)
                    {
                        string filepath = Path.Combine(hostingenvironment.WebRootPath, "images", model.ExistingPhotoPath);
                        System.IO.File.Delete(filepath);
                    }
                    //string uniqueFilename = ProcesUploadedFile(model);
                    employee.PhotoPath = ProcesUploadedFile(model);
                }



                //Employee newEmployee = new Employee
                //{
                //    Name = model.Name,
                //    Email = model.Email,
                //    Department = model.Department,
                //    PhotoPath = uniqueFilename
                //};
                //_employeeRepository.Update(newEmployee);
                _employeeRepository.Update(employee);
                //return RedirectToAction("details", new { id = newEmployee.Id });
                return(RedirectToAction("index"));
            }

            return(View());
        }