public HttpResponseMessage Get() { try { // Below is how you can log the information Logger.Information("ToDoController Request Get: Enter into the method"); var items = _toDoBL.GetItemCount(); var response = Request.CreateResponse(HttpStatusCode.OK); if (null != items) { response.Content = new StringContent(items, Encoding.UTF8, "application/json"); } else { response.Content = new StringContent("0", Encoding.UTF8, "application/json"); } return(response); } catch (Exception ex) { var message = Request.CreateResponse(HttpStatusCode.InternalServerError); Logger.Error("ToDoController Unable to consume Get:" + ex.Message + ex.StackTrace); return(message); } finally { //This is to dispose the object Dispose(); } }
public JsonResult GetItemCount() { string result = string.Empty; try { string item = _toDoService.GetItemCount(); string itemCount = (string.IsNullOrEmpty(item)) ? "0" : item; return(Json(itemCount, JsonRequestBehavior.AllowGet)); } catch (Exception ex) { Logger.Error("CacheController Unable to consume GetItemCount:" + ex.Message + ex.StackTrace); result = "error"; } finally { Dispose(); } return(Json(result, JsonRequestBehavior.AllowGet)); }