public async Task <ActionResult> Update(ToDoItem item) { try { Analytics.TrackEvent("ToDoController:Update"); if (ModelState.IsValid & !string.IsNullOrEmpty(item.Id)) { await _toDoService.Update(item); } else { Logger.Error("ToDoController Create: Invalid data" + JsonConvert.SerializeObject(item)); return(RedirectToAction("Index", "Error")); } } catch (Exception ex) { Logger.Error("ToDoController Unable to consume Create:" + ex.Message + ex.StackTrace); return(RedirectToAction("Index", "Error")); } finally { //This is to dispose the object Dispose(); } return(RedirectToAction("Index")); }
public async Task <HttpResponseMessage> Put(ToDoItem model) { try { if (ModelState.IsValid && !String.IsNullOrEmpty(model.Id)) { Logger.Information("ToDoController Request Update:" + JsonConvert.SerializeObject(model)); var status = await _toDoBL.Update(model); if (status) { Logger.Information("ToDoController Response Update:" + JsonConvert.SerializeObject(model)); var message = Request.CreateResponse(HttpStatusCode.Accepted, "Record has been updated"); return(message); } } return(Request.CreateResponse(HttpStatusCode.BadRequest)); } catch (Exception ex) { Logger.Error("ToDoController Unable to consume Update:" + ex.Message + ex.StackTrace); var message = Request.CreateResponse(HttpStatusCode.InternalServerError); return(message); } finally { //This is to dispose the object Dispose(); } }
public HttpResponseMessage Put(ToDoItem model) { try { if (ModelState.IsValid && model.Id > 0) { var status = _toDoBL.Update(model); if (status) { var message = Request.CreateResponse(HttpStatusCode.OK, "Updated Successfully"); return(message); } else { return(Request.CreateResponse(HttpStatusCode.BadRequest)); } } else { return(Request.CreateResponse(HttpStatusCode.BadRequest)); } } catch (Exception ex) { Logger.Error("ToDoController Unable to consume Update:" + ex.Message + ex.StackTrace); var message = Request.CreateResponse(HttpStatusCode.InternalServerError); return(message); } finally { //This is to dispose the object Dispose(); } }
public async Task <JsonResult> Update(ToDoItem item) { string result = string.Empty; bool status = false; try { Analytics.TrackEvent("ToDoController:Update"); if (ModelState.IsValid & !string.IsNullOrEmpty(item.Id)) { status = await _toDoBL.Update(item); if (status) { return(Json(new { data = item }, JsonRequestBehavior.AllowGet)); } else { result = "Error"; } } else { Logger.Error("ToDoController Create: Invalid data" + JsonConvert.SerializeObject(item)); result = "Error"; } } catch (Exception ex) { Logger.Error("ToDoController Unable to consume Create:" + ex.Message + ex.StackTrace); result = "Error"; } finally { //This is to dispose the object Dispose(); } return(Json(result, JsonRequestBehavior.AllowGet)); }
public JsonResult Update(ToDoItem item) { string result = string.Empty; bool status = false; try { if (ModelState.IsValid && item.Id > 0) { status = _toDoService.Update(item); if (!status) { Logger.Error("ToDoController Create: Invalid data" + JsonConvert.SerializeObject(item)); result = "error"; } else { return(Json(new { data = item }, JsonRequestBehavior.AllowGet)); } } else { Logger.Error("ToDoController Create: Invalid data" + JsonConvert.SerializeObject(item)); result = "error"; } } catch (Exception ex) { Logger.Error("ToDoController Unable to consume Create:" + ex.Message + ex.StackTrace); result = "error"; } finally { //This is to dispose the object Dispose(); } return(Json(result, JsonRequestBehavior.AllowGet)); }
public IActionResult Update([FromBody] ToDoItem item) { string result = string.Empty; bool status = false; try { if (ModelState.IsValid && !string.IsNullOrEmpty(item.Id)) { status = _toDoService.Update(item); if (!status) { _logger.LogError("ToDoController Create: Invalid data" + JsonConvert.SerializeObject(item)); result = "error"; } else { return(Json(new { data = item })); } } else { _logger.LogError("ToDoController Create: Invalid data" + JsonConvert.SerializeObject(item)); result = "error"; } } catch (Exception ex) { _logger.LogError("ToDoController Unable to consume Create:" + ex.Message + ex.StackTrace); result = "error"; } finally { //This is to dispose the object Dispose(); } return(Json(result)); }