Esempio n. 1
0
 public HttpResponseMessage PostStudent(Student student)
 {
     var studentToModify = EventRepository.Students.FirstOrDefault(_ => _.Id == student.Id);
     studentToModify.FirstName = student.FirstName;
     studentToModify.LastName = student.LastName;
     studentToModify.Password = student.Password;
     studentToModify.Bio = student.Bio;
     EventRepository.SaveChanges();
     var response = Request.CreateResponse<Student>(HttpStatusCode.Created, student);
     string uri = Url.Link("http://eventid.rodrigueh.com/api/Student/", new { id = student.Id });
     response.Headers.Location = new Uri(uri);
     return response;
 }
Esempio n. 2
0
 public HttpResponseMessage PutStudent(Student student)
 {
     if (EventRepository.Students.FirstOrDefault(_=>_.Email == student.Email) != null)
     {
         return Request.CreateErrorResponse(HttpStatusCode.Unauthorized, "Email already exists");
     }
     else
     {
         if (ModelState.IsValid)
         {
             EventRepository.Students.Add(student);
             EventRepository.SaveChanges();
             var studentToReturn = EventRepository.Students.FirstOrDefault(_ => _.Email == student.Email);
             var response = Request.CreateResponse<Student>(HttpStatusCode.Created, studentToReturn);
             string uri = Url.Link("http://eventid.rodrigueh.com/api/Student/", new { id = student.Id });
         }
         return Request.CreateResponse(HttpStatusCode.OK);
     }
 }