public async Task <IActionResult> Edit(int id, [Bind("Id,Name")] Matter matter) { if (id != matter.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(matter); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!MatterExists(matter.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(matter)); }
public async Task <IActionResult> Edit(int id, [Bind("StudentId,MatterId,EnrollmentDate")] StudentMatter studentMatter) { if (id != studentMatter.StudentId) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(studentMatter); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!StudentMatterExists(studentMatter.StudentId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["MatterId"] = new SelectList(_context.Matters, "Id", "Id", studentMatter.MatterId); ViewData["StudentId"] = new SelectList(_context.Students, "Id", "Id", studentMatter.StudentId); return(View(studentMatter)); }
public async Task <IActionResult> Edit(int id, [Bind("Id,Name,Age,Year,CareerId,NamePhoto")] Student student) { if (id != student.Id) { return(NotFound()); } if (ModelState.IsValid) { var files = HttpContext.Request.Form.Files; if (files != null && files.Count > 0) { var filesPhoto = files[0]; var pathDesitine = Path.Combine(env.WebRootPath, "images\\students"); if (filesPhoto.Length > 0) { var fileDestine = Guid.NewGuid().ToString().Replace("-", "") + Path.GetExtension(filesPhoto.FileName); using (var filestream = new FileStream(Path.Combine(pathDesitine, fileDestine), FileMode.Create)) { filesPhoto.CopyTo(filestream); string oldFile = Path.Combine(pathDesitine, student.NamePhoto ?? ""); if (System.IO.File.Exists(oldFile)) { System.IO.File.Delete(oldFile); } student.NamePhoto = fileDestine; }; } } try { _context.Update(student); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!StudentExists(student.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["CareerId"] = new SelectList(_context.Careers, "Id", "Description", student.CareerId); return(View(student)); }