示例#1
0
        public IActionResult Edit(EditPeopleViewModel model)
        //public RedirectToActionResult Create(People people)
        {
            if (ModelState.IsValid)
            {
                // Retrieve the employee being edited from the database
                People people = _people.GetPeople(model.Id);
                // Update the employee object with the data in the model object
                people.Name = model.Name;
                people.Email = model.Email;
                people.Department = model.Department;

                if (model.Photos != null && model.Photos.Count > 0)
                {
                    // If a new photo is uploaded, the existing photo must be
                    // deleted. So check if there is an existing photo and delete
                    if (model.ExistingPhotoPath != null)
                    {
                        string filePath = Path.Combine(hostingEnvironment.WebRootPath,
                            "images", model.ExistingPhotoPath);
                        System.IO.File.Delete(filePath);
                    }
                    // Save the new photo in wwwroot/images folder and update
                    // PhotoPath property of the employee object which will be
                    // eventually saved in the database
                    
                    people.PhotoPath = ProcessUploadedFile(model);
                }
               




                _people.UpdatePeople(people);
                return RedirectToAction("Index", new { id = people.Id });
            }
            return View();

        }