// POST: api/Student public async Task <HttpResponseMessage> PostAsync([FromBody] Student.Data.Models.Student newStudent) { var data = await studentsRepo.AddStudentAsync(newStudent); return(new HttpResponseMessage(HttpStatusCode.OK) { Content = new ObjectContent <object>(new { Message = "new student created" }, Configuration.Formatters.JsonFormatter) }); }
// PUT: api/Student/5 public async Task <HttpResponseMessage> PutAsync(Guid id, [FromBody] Student.Data.Models.Student student) { student.ID = id; var data = await studentsRepo.UpdateStudentAsync(student); return(new HttpResponseMessage(HttpStatusCode.OK) { Content = new ObjectContent <object>(new { Message = "the student updated successfully" }, Configuration.Formatters.JsonFormatter) }); }
public async Task <bool> UpdateStudent(Student.Data.Models.Student student) { bool updated = false; string strPayload = JsonConvert.SerializeObject(student); HttpContent c = new StringContent(strPayload, Encoding.UTF8, "application/json"); HttpResponseMessage response = await _httpclient.PutAsync("api/student/" + student.ID, c).ConfigureAwait(false); if (response.IsSuccessStatusCode) { var contents = await response.Content.ReadAsStringAsync(); updated = true; } return(updated); }
public async Task <Student.Data.Models.Student> AddStudent(Student.Data.Models.Student student) { student.ID = Guid.NewGuid(); string strPayload = JsonConvert.SerializeObject(student); HttpContent c = new StringContent(strPayload, Encoding.UTF8, "application/json"); HttpResponseMessage response = await _httpclient.PostAsync("api/student/", c).ConfigureAwait(false); if (response.IsSuccessStatusCode) { var contents = await response.Content.ReadAsStringAsync(); return(student); } return(new Student.Data.Models.Student()); }
public async Task <Student.Data.Models.Student> AddStudent(Student.Data.Models.Student student) { student.ID = Guid.NewGuid(); _workerQueueProducer.SendMessage(student, "add"); /*string strPayload = JsonConvert.SerializeObject(student); * HttpContent c = new StringContent(strPayload, Encoding.UTF8, "application/json"); * HttpResponseMessage response = await _httpclient.PostAsync("api/student/", c).ConfigureAwait(false); * if (response.IsSuccessStatusCode) * { * var contents = await response.Content.ReadAsStringAsync(); * return student; * }*/ return(student); }