public void UpdateStudent(string studentId, StudentEditInputModel editModel) { var student = Repositories.Students.Query() .AsNoTracking() .SingleOrDefault(s => s.Id == studentId); if (student == null) { throw new TargetException("Student does not exist"); } var newData = Mapper.Map <StudentEditInputModel, Student>(editModel); newData.Id = studentId; newData.StartYear = student.StartYear; Repositories.Students.Update(newData); }
public async Task <IActionResult> Edit(StudentEditInputModel model) { if (this.ModelState.IsValid) { StudentServiceModel serviceModel = model.To <StudentServiceModel>(); bool result = await this.studentService.EditStudentAsync(serviceModel); if (result) { return(this.RedirectToAction("All")); } } var studentClass = await this.classService.GetStudentClassDropdownAsync(model.Id); this.ViewBag.StudentClass = studentClass; return(this.View(model)); }
public async Task <IActionResult> EditStudent(StudentEditInputModel model) { if (this.ModelState.IsValid) { var serviceModel = model.To <StudentServiceModel>(); var result = await this.studentService.EditStudentAsync(serviceModel); if (result) { return(this.RedirectToAction("StudentsAll", new { id = model.ClassId })); } } string classFullName = await this.classService.GetClassNameByIdAsync(model.ClassId); string classId = model.ClassId; this.ViewBag.ClassName = classFullName; this.ViewBag.ClassId = classId; return(this.View(model)); }
public void Update([FromRoute] string studentId, [FromBody] StudentEditInputModel editModel) { _studentService.UpdateStudent(studentId, editModel); }