public HttpResponseMessage Update([FromBody] StudentAPIModel studentAPIModel) { if (studentAPIModel == null) { return(Request.CreateResponse(HttpStatusCode.BadRequest)); } if (_iStudentService.CheckIsStudentExists(studentAPIModel.Username) == true) { _iStudentService.UpdateStudent(_iStudentAPIMapper.Map(studentAPIModel)); return(Request.CreateResponse(HttpStatusCode.Created, _iStudentAPIMapper.Map(studentAPIModel))); } else { return(Request.CreateErrorResponse(HttpStatusCode.Conflict, "Student is not enrolled in this class!")); } }
public HttpResponseMessage Create([FromBody] StudentAPIModel studentAPIModel) { if (_iStudentService.GetByUsername(_iStudentAPIMapper.Map(studentAPIModel).Username) != null) { return(Request.CreateErrorResponse(HttpStatusCode.Conflict, "Username already used!")); } else if (studentAPIModel == null) { return(Request.CreateResponse(HttpStatusCode.BadRequest)); } else { _iStudentService.AddStudent(_iStudentAPIMapper.Map(studentAPIModel)); return(Request.CreateResponse(HttpStatusCode.Created, _iStudentAPIMapper.Map(studentAPIModel))); } }
public StudentModel Map(StudentAPIModel studentAPIModel) { if (studentAPIModel == null) { return(null); } return(new StudentModel { Token = studentAPIModel.Token, Username = studentAPIModel.Username, EncPassword = studentAPIModel.EncPassword, Name = studentAPIModel.Name, Email = studentAPIModel.Email, GroupNo = studentAPIModel.GroupNo, Hobby = studentAPIModel.Hobby }); }