Exemplo n.º 1
0
 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"));
 }
Exemplo n.º 2
0
        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();
            }
        }
Exemplo n.º 3
0
 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();
     }
 }
Exemplo n.º 4
0
        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));
        }
Exemplo n.º 5
0
        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));
        }
Exemplo n.º 6
0
        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));
        }