public IHttpActionResult EditFormData(int id, [FromBody] WidgetClassModels.Update widgetClass)
        {
            JavaScriptSerializer js = new JavaScriptSerializer();
            string logForm          = "Form : " + js.Serialize(widgetClass);
            string logAPI           = "[Put] " + Request.RequestUri.ToString();

            if (!ModelState.IsValid || widgetClass == null)
            {
                Startup._sfAppLogger.Warn(logAPI + " || Input Parameter not expected || " + logForm);
                return(BadRequest("Invalid data"));
            }

            try
            {
                WidgetClassModels widgetClassModel = new WidgetClassModels();
                widgetClassModel.updateWidgetClass(id, widgetClass);
                return(Ok("Success"));
            }
            catch (Exception ex)
            {
                StringBuilder logMessage = LogUtility.BuildExceptionMessage(ex);
                logMessage.AppendLine(logForm);
                Startup._sfAppLogger.Error(logAPI + logMessage);

                return(InternalServerError(ex));
            }
        }
        public IHttpActionResult AddFormData([FromBody] WidgetClassModels.Add widgetClass)
        {
            string logForm = "Form : " + Startup._jsSerializer.Serialize(widgetClass);
            string logAPI  = "[Post] " + Request.RequestUri.ToString();

            if (!ModelState.IsValid || widgetClass == null)
            {
                Startup._sfAppLogger.Warn(logAPI + " || Input Parameter not expected || " + logForm);
                return(BadRequest("Invalid data"));
            }

            try
            {
                WidgetClassModels widgetClassModel = new WidgetClassModels();
                int newWidgetClassId = widgetClassModel.addWidgetClass(widgetClass);
                return(Json(new { id = newWidgetClassId }));
            }
            catch (Exception ex)
            {
                StringBuilder logMessage = LogUtility.BuildExceptionMessage(ex);
                logMessage.AppendLine(logForm);
                Startup._sfAppLogger.Error(logAPI + logMessage);

                return(InternalServerError(ex));
            }
        }
        public IHttpActionResult GeById(int id)
        {
            WidgetClassModels widgetClassModel = new WidgetClassModels();

            try
            {
                WidgetClassModels.Detail widgetClass = widgetClassModel.getWidgetClassById(id);
                return(Ok(widgetClass));
            }
            catch
            {
                return(NotFound());
            }
        }
 public IHttpActionResult Delete(int id)
 {
     try
     {
         WidgetClassModels widgetClassModel = new WidgetClassModels();
         widgetClassModel.deleteWidgetClass(id);
         return(Ok("Success"));
     }
     catch (Exception ex)
     {
         string        logAPI     = "[Delete] " + Request.RequestUri.ToString();
         StringBuilder logMessage = LogUtility.BuildExceptionMessage(ex);
         Startup._sfAppLogger.Error(logAPI + logMessage);
         return(InternalServerError());
     }
 }