// GET: CrimeMaintance/Edit/5 public async Task <ActionResult> Edit(int id) { var crime = new CrimeMantainainceDTO(); try { var requestUrl = $"{BaseUrl}{apiUri}/GetCrime?id={id}"; using (var client = new HttpClient()) { client.BaseAddress = new Uri(requestUrl); var response = await client.GetAsync(requestUrl); if (response.StatusCode != HttpStatusCode.OK) { ViewBag.Message = "Something went wrong, try again"; return(View()); } crime = await response.Content.ReadAsAsync <CrimeMantainainceDTO>(); } return(View(crime)); } catch (Exception ex) { throw new Exception(ex.Message); } }
public async Task <ActionResult> Edit(CrimeMantainainceDTO collection) { var outputHandler = new OutputHandler(); var requestUrl = $"{BaseUrl}{apiUri}/edit"; using (var client = new HttpClient()) { client.BaseAddress = new Uri(requestUrl); HttpResponseMessage response = await client.PutAsJsonAsync(requestUrl, collection); outputHandler = await response.Content.ReadAsAsync <OutputHandler>(); if (response.StatusCode != HttpStatusCode.OK) { if (outputHandler.IsErrorOccured) { ViewBag.Message = outputHandler.Message; return(View()); } } } return(RedirectToAction("Index", new { outputHandler.Message })); }