private string getFinleName(StudentEditViewModelClass model, string filename) { if (model.PhotoPath != null) { string uploads = Path.Combine( histingEnviroment.WebRootPath, "images" ); filename = Guid.NewGuid().ToString() + "_" + model.PhotoPath.FileName.ToString(); string filePath = Path.Combine(uploads, filename); model.PhotoPath.CopyTo(new FileStream(filePath, FileMode.Create)); } return(filename); }
public ViewResult Edit(int id) { try { Student st = _repository.GetStudents(id); StudentEditViewModelClass editViewModelClass = new StudentEditViewModelClass() { ExistingPhotoPath = st.PhotoPath, Address = st.Address, Division = st.Division, FullName = st.FullName, Id = id }; return(View(editViewModelClass)); } catch (Exception ex) { Console.WriteLine(ex); throw; } }
public IActionResult Edit(StudentEditViewModelClass model) { if (ModelState.IsValid) { string filename = null; Student student = _repository.GetStudents(model.Id); filename = getFinleName(model, filename); student.FullName = model.FullName; student.Address = model.Address; student.Division = model.Division; student.PhotoPath = filename; var st = _repository.UpdateStudent(student); // return RedirectToAction("Details", new {id = st.StudentId}); return(RedirectToAction("Details", new { id = student.StudentId })); } return(View("Edit")); }