public ActionResult Put(Guid id, [FromBody] StudentRequest request) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } try { var student = studentRepository.Get(id); if (student != null) { student.FirstName = request.FirstName; student.MiddleName = request.MiddleName; student.LastName = request.LastName; student.BirthDate = request.BirthDate; student.Gender = Gender.FromId(request.Gender) ?? Gender.NotSpecified; student.GPA = request.Gpa; this.studentRepository.Update(student); return(Ok()); //TODO: Add audit info in response //var response = new UpdateStudentResponse(student.Id); //return Ok(response); } return(NotFound()); } catch (Exception e) { return(GenericServerErrorResult(e)); } }
public ActionResult Put(Guid id, [FromBody] TeacherRequest request) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } try { var teacher = teacherRepository.Get(id); if (teacher != null) { teacher.FirstName = request.FirstName; teacher.MiddleName = request.MiddleName; teacher.LastName = request.LastName; teacher.BirthDate = request.BirthDate; teacher.Gender = Gender.FromId(request.Gender) ?? Gender.NotSpecified; teacher.Title = NameTitle.FromId(request.Title) ?? NameTitle.None; this.teacherRepository.Update(teacher); return(Ok()); //TODO: Add audit info in response //var response = new UpdateTeacherResponse(teacher.Id); //return Ok(response); } return(NotFound()); } catch (Exception e) { return(GenericServerErrorResult(e)); } }
public ActionResult <NewRecordResponse> Post([FromBody] StudentRequest request) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } try { var student = new Student { FirstName = request.FirstName, MiddleName = request.MiddleName, LastName = request.LastName, BirthDate = request.BirthDate, Gender = Gender.FromId(request.Gender) ?? Gender.NotSpecified, GPA = request.Gpa }; this.studentRepository.Create(student); var response = new NewRecordResponse(student.Id); return(CreatedAtAction(nameof(Get), new { id = student.Id }, response)); } catch (Exception e) { return(GenericServerErrorResult(e)); } }
public ActionResult <NewRecordResponse> Post([FromBody] TeacherRequest request) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } try { var teacher = new Teacher { FirstName = request.FirstName, MiddleName = request.MiddleName, LastName = request.LastName, BirthDate = request.BirthDate, Gender = Gender.FromId(request.Gender) ?? Gender.NotSpecified, Title = NameTitle.FromId(request.Title) ?? NameTitle.None }; this.teacherRepository.Create(teacher); var response = new NewRecordResponse(teacher.Id); return(CreatedAtAction(nameof(Get), new { id = teacher.Id }, response)); } catch (Exception e) { return(GenericServerErrorResult(e)); } }