Beispiel #1
0
 public void Set(Exception exception)
 {
     this.errMessage = ExceptionProcs.GetExceptionMessage(exception);
     this.stackTrace = ExceptionProcs.GetStackTrace(exception);
 }
        public ActionResult EditApplication(FormCollection model, string Create, string Delete, string Save)
        {
            System.Threading.Thread.Sleep(500);

            if (!ModelState.IsValid)
            {
                Dictionary <String, String> err_list = GetModelErrors.GetErrors(ModelState);
                dynamic errorMessage = new { param1 = err_list.ToList()[0].Key, param2 = err_list.ToList()[0].Value };
                HttpContext.Response.StatusCode = (int)HttpStatusCode.NotAcceptable;
                return(Json(errorMessage, JsonRequestBehavior.AllowGet));
            }

            try
            {
                string    tmpJson   = model.ToJSON();
                AppSystem tmpSystem = new AppBuilder().Build(tmpJson);
                dynamic   jsonMessage;
                if (!String.IsNullOrEmpty(Delete))
                {
                    SecAppManager.Delete(tmpSystem);
                    HttpContext.Response.StatusCode = (int)HttpStatusCode.OK;
                    jsonMessage = new { param1 = "Deleted", param2 = tmpSystem.Name };
                    return(Json(jsonMessage, JsonRequestBehavior.AllowGet));
                }
                else if (!String.IsNullOrEmpty(Create))
                {
                    AppSystem newSystem = SecAppManager.Create(tmpSystem);
                    string    appJson   = newSystem.ToJSON();
                    jsonMessage = new {
                        param1 = "Created",
                        newSystem.Id,
                        newSystem.AppId,
                        newSystem.Name,
                        newSystem.Desc,
                        CreateDate = newSystem.CreateDate.ToShortDateString() + " " + newSystem.CreateDate.ToShortTimeString(),
                        UpdateDate = newSystem.UpdateDate.ToShortDateString() + " " + newSystem.UpdateDate.ToShortTimeString()
                    };
                    return(Json(jsonMessage, JsonRequestBehavior.AllowGet));
                }
                else if (!String.IsNullOrEmpty(Save))
                {
                    AppSystem updSystem = SecAppManager.Update(tmpSystem);
                    HttpContext.Response.StatusCode = (int)HttpStatusCode.OK;
                    jsonMessage = new
                    {
                        param1 = "Updated",
                        updSystem.Id,
                        updSystem.AppId,
                        updSystem.Name,
                        updSystem.Desc,
                        CreateDate = updSystem.CreateDate.ToShortDateString() + " " + updSystem.CreateDate.ToShortTimeString(),
                        UpdateDate = updSystem.UpdateDate.ToShortDateString() + " " + updSystem.UpdateDate.ToShortTimeString()
                    };
                    return(Json(jsonMessage, JsonRequestBehavior.AllowGet));
                }
                else
                {
                    HttpContext.Response.StatusCode = (int)HttpStatusCode.NotImplemented;
                    jsonMessage = new { param1 = "Error", param2 = "Uknown function call" };
                    return(Json(jsonMessage, JsonRequestBehavior.AllowGet));
                }
            }
            catch (Exception ex)
            {
                dynamic jsonMessage;
                HttpContext.Response.StatusCode = (int)HttpStatusCode.Forbidden;
                string errMessage = ExceptionProcs.GetExceptionMessage(ex);
                if (errMessage.Contains("duplicate"))
                {
                    jsonMessage = new { param1 = "Error", param2 = "Already Exists" };
                }
                else
                {
                    jsonMessage = new { param1 = "Error", param2 = errMessage };
                }
                return(Json(jsonMessage, JsonRequestBehavior.AllowGet));
            }
        }