public IHttpActionResult UpdateStudentMobile(UpdateStudentMob upd) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } TestWebAPI.STUDENT_MST student = null; student = ctx.STUDENT_MST.Where(c => c.SM_ID == upd.stud_id).FirstOrDefault(); if (student == null) { return(NotFound()); } student.SM_MOBILE = upd.stud_mobile; ctx.SaveChanges(); return(Ok("success")); }
public IHttpActionResult UpdStudentMobile_EntryDate1(bool updateEntryDate, UpdateStudentMob stud) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } TestWebAPI.STUDENT_MST student = null; student = ctx.STUDENT_MST.Where(c => c.SM_ID == stud.stud_id).FirstOrDefault(); if (student == null) { return(NotFound()); } student.SM_MOBILE = stud.stud_mobile; if (updateEntryDate) { student.SM_ENTRYDATE = DateTime.Now; } ctx.SaveChanges(); return(Ok("success")); }
public async Task <string> UpdateStudMobile(string studid, string mobile) { string Response = ""; try { HttpResponseMessage HttpResponseMessage = null; using (var httpClient = new HttpClient()) { httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); //application/xml UpdateStudentMob obj = new UpdateStudentMob() { stud_id = studid, stud_mobile = mobile }; JavaScriptSerializer jss = new JavaScriptSerializer(); // serialize into json string var myContent = jss.Serialize(obj); var httpContent = new StringContent(myContent, System.Text.Encoding.UTF8, "application/json"); HttpResponseMessage = await httpClient.PostAsync("http://localhost:50875/api/School", httpContent); if (HttpResponseMessage.StatusCode == HttpStatusCode.OK) { Response = HttpResponseMessage.Content.ReadAsStringAsync().Result; } else { Response = "Some error occured." + HttpResponseMessage.StatusCode; } } } catch (Exception ex) { return(ex.Message); } return(Response); }