private async Task <HttpResponseMessage> HttpPut(HttpControllerContext controllerContext) // if Put Request Method { HttpResponseMessage retVal = null; string contentAsString = await controllerContext.Request.Content.ReadAsStringAsync(); StudentMember postedStudentMember = await Newtonsoft.Json.JsonConvert.DeserializeObjectAsync <StudentMember>(contentAsString); if (StudentMemberRepositories.IsExist(postedStudentMember.FullName)) { retVal = controllerContext.Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Unable to find Student Member with given Id"); } else { StudentMemberRepositories.Update(postedStudentMember); retVal = controllerContext.Request.CreateResponse(HttpStatusCode.OK, postedStudentMember); } return(retVal); }
private async Task <HttpResponseMessage> HttpPost(HttpControllerContext controllerContext)// if Post Request Method { HttpResponseMessage retVal = null; string contentAsString = await controllerContext.Request.Content.ReadAsStringAsync(); StudentMember postedStudentMember = await Newtonsoft.Json.JsonConvert.DeserializeObjectAsync <StudentMember>(contentAsString); if (StudentMemberRepositories.IsExist(postedStudentMember.FullName)) { retVal = controllerContext.Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Another Studen member the same Fullnam is already exist."); } else { StudentMember studentMember = StudentMemberRepositories.Add(postedStudentMember.FullName, postedStudentMember.Age, postedStudentMember.Section , postedStudentMember.ClassNumber); retVal = controllerContext.Request.CreateResponse(HttpStatusCode.OK, studentMember); } return(retVal); }
private HttpResponseMessage HttpDelete(HttpControllerContext controllerContext) //Delete Request Method { HttpResponseMessage retVal = null; var id = controllerContext.RouteData.Values["id"]; // Gelen Get İsteğinde Gelen Parametreyi Alıyoruz. if (id == null) { retVal = controllerContext.Request. CreateErrorResponse(HttpStatusCode.BadRequest, "Cannot call this metod withot Id.");; } else { int idAsInteger; if (!int.TryParse(id.ToString(), out idAsInteger)) { retVal = controllerContext.Request. CreateErrorResponse(HttpStatusCode.BadRequest, "Id must be a numaric value."); } else { if (StudentMemberRepositories.IsExist(idAsInteger)) { retVal = controllerContext.Request. CreateErrorResponse(HttpStatusCode.BadRequest, "Unable to find Student Member with given Id."); } else { StudentMemberRepositories.Remove(idAsInteger); retVal = controllerContext.Request. CreateResponse(HttpStatusCode.OK); } } } return(retVal); }