Exemplo n.º 1
0
 public HttpResponseMessage PutStudent(int id, Student student)
 {
     student.id = id;
     if (!studentRepository.Update(student))
     {
         return Request.CreateErrorResponse(HttpStatusCode.NotFound, "Unable to Update the Student for the Given ID");
     }
     else
     {
         return Request.CreateResponse(HttpStatusCode.OK);
     }
 }
Exemplo n.º 2
0
 public bool Update(Student student)
 {
     if (student == null)
     {
         throw new ArgumentNullException("student");
     }
     int index = students.FindIndex(s => s.id == student.id);
     if (index == -1)
     {
         return false;
     }
     students.RemoveAt(index);
     students.Add(student);
     return true;
 }
Exemplo n.º 3
0
 public HttpResponseMessage PostStudent(Student student)
 {
     bool result = studentRepository.Add(student);
     if (result)
     {
         var response = Request.CreateResponse<Student>(HttpStatusCode.Created, student);
         string uri = Url.Link("DefaultApi", new { id = student.id });
         response.Headers.Location = new Uri(uri);
         return response;
     }
     else
     {
         return Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Student Not Added");
     }
 }
Exemplo n.º 4
0
 public bool Add(Student student)
 {
     bool addResult = false;
     if (student == null)
     {
         return addResult;
     }
     int index = students.FindIndex(s => s.id == student.id);
     if (index == -1)
     {
         students.Add(student);
         addResult = true;
         return addResult;
     }
     else
     {
         return addResult;
     }
 }