Example #1
0
        public JsonResult AddTest(string SessionGuid, Test Test)
        {
            try
            {
                var validSession = DbHelpers.SessionIsValid(SessionGuid);
                if (!validSession)
                {
                    return(Json(
                               new JsonResponse <bool>
                    {
                        Response = false,
                        Success = false,
                        Message = "Invalid Session. Try logging out and then loggin back in. No changes were saved."
                    },
                               JsonRequestBehavior.AllowGet
                               ));
                }
                bool Success = false;
                if (Test == null)
                {
                    return(Json(
                               new JsonResponse <bool>
                    {
                        Response = Success,
                        Success = false,
                        Message = "Test==null"
                    },
                               JsonRequestBehavior.AllowGet
                               ));
                }

                Success = DbHelpers.AddTest(Test);
                return(Json(
                           new JsonResponse <bool>
                {
                    Response = Success,
                    Success = Success,
                    Message = Success?"Test added!": "An error occurred while adding the test."
                },
                           JsonRequestBehavior.AllowGet
                           ));
            }
            catch (Exception e)
            {
                return(Json(
                           new JsonResponse <bool>
                {
                    Response = false,
                    Success = false,
                    Message = e.Message
                },
                           JsonRequestBehavior.AllowGet
                           ));
            }
        }