public async Task <IActionResult> EditSpeaker(int?id, SpeakerVM speakerVM, IFormFile File) { if (id == null) { return(NotFound()); } Speaker speaker = await _db.Speakers.FindAsync(id); if (speaker == null) { return(NotFound()); } speakerVM.Image = speaker.Image; if (File != null) { if (!File.isImage()) { ModelState.AddModelError(string.Empty, "Choose photo"); return(View(speakerVM)); } Helpers.Helper.DeleteIMG(_env.WebRootPath, "img/event", speaker.Image); speaker.Image = await File.SaveImg(_env.WebRootPath, "img/event"); } speaker.Name = speakerVM.Name; speaker.Speciality = speakerVM.Speciality; await _db.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); }
public async Task <IActionResult> EditSpeaker(int?id) { if (id == null) { return(NotFound()); } Speaker speaker = await _db.Speakers.FindAsync(id); if (speaker == null) { return(NotFound()); } SpeakerVM speakerVM = new SpeakerVM { Image = speaker.Image, Name = speaker.Name, Speciality = speaker.Speciality }; return(View(speakerVM)); }