//POST: api/Students/Login public HttpResponseMessage StudentLoginAttempt([FromBody] LoginRequest data, [FromUri] int?id) { Student student = db.Students.Where(x => x.LoginMail == data.Mail).FirstOrDefault(); if (student != null) { if (student.LoginPassword == data.Password) { InternalCodeResponse response = new InternalCodeResponse(VERIFIED, student.ID); int teacherID = db.Teachers.Where(entry => entry.ClassID == student.ClassID).FirstOrDefault().ID; return(Request.CreateResponse(HttpStatusCode.OK, new StudentLoginResponse(response, teacherID))); } else { InternalCodeResponse response = new InternalCodeResponse(WRONG_PASSWORD, null); return(Request.CreateResponse(HttpStatusCode.OK, new StudentLoginResponse(response, null))); } } else { InternalCodeResponse response = new InternalCodeResponse(NONEXSISTENT_USERNAME, null); return(Request.CreateResponse(HttpStatusCode.OK, new StudentLoginResponse(response, null))); } }
public StudentLoginResponse(InternalCodeResponse _response, int?_teacherID) { this.Response = _response; this.TeacherID = _teacherID; }