Пример #1
0
        public async Task <HttpResponseMessage> Get()
        {
            try
            {
                // Below is how you can log the information
                Logger.Information("ToDoController Request Get: Enter into the method");
                var items = await _toDoBL.GetAll();

                string json = string.Empty;
                if (null != items)
                {
                    json = JsonConvert.SerializeObject(items);
                    var response = this.Request.CreateResponse(HttpStatusCode.OK);
                    response.Content = new StringContent(json, Encoding.UTF8, "application/json");
                    return(response);
                }
                Logger.Information("ToDoController Response Get:  Exit from the method");
                return(Request.CreateResponse(HttpStatusCode.NotFound));
            }
            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();
            }
        }
Пример #2
0
        public JsonResult GetAll()
        {
            string result = string.Empty;

            try
            {
                return(Json(new { data = _toDoService.GetAll() }, JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                Logger.Error("HomeController Unable to consume GetAll:" + ex.Message + ex.StackTrace);
                result = "error";
            }
            finally
            {
                Dispose();
            }
            return(Json(result, JsonRequestBehavior.AllowGet));
        }
Пример #3
0
        public async Task <JsonResult> GetAll()
        {
            //Below is how you can log the information
            Logger.Information("ToDoController Index Enter into method");
            string result = string.Empty;

            try
            {
                return(Json(new { data = await _toDoBL.GetAll() }, JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                Logger.Error("ToDoController Unable to consume Index:" + ex.Message + ex.StackTrace);
                result = "Error";
            }
            finally
            {
                //This is to dispose the object
                Dispose();
            }
            return(Json(result, JsonRequestBehavior.AllowGet));
        }
Пример #4
0
        /// <summary>
        /// This is the default page which will run when the application start
        /// In this we are loading all the todo's items and returning that todolist to view
        /// </summary>
        /// <returns>If this is success it will rediect to index page otherwise error page</returns>
        public async Task <ActionResult> Index()
        {
            //Below is how you can log the information
            Logger.Information("ToDoController Index Enter into method");
            Analytics.TrackEvent("ToDoController:Index");
            var form = new ToDoList();

            try
            {
                form.Items = await _toDoService.GetAll();
            }
            catch (Exception ex)
            {
                Logger.Error("ToDoController Unable to consume Index:" + ex.Message + ex.StackTrace);
                return(RedirectToAction("Index", "Error"));
            }
            finally
            {
                //This is to dispose the object
                Dispose();
            }
            return(View(form));
        }