public ActionResult GetIncidents2(int queryId)
        {
            if (queryId < 1)
            {
                return(Json(new List <IncidentReportObject>(), JsonRequestBehavior.AllowGet));
            }

            var query = new IncidentQueryBuilderServices().GetIncidentQuery(queryId);

            if (query == null || query.IncidentQueryId < 1)
            {
                return(Json(new List <IncidentReportObject>(), JsonRequestBehavior.AllowGet));
            }

            var incidentList = new IncidentHistoryServices().GetOrderedIncidentReportObjects(query) ?? new List <IncidentReportObject>();

            if (!incidentList.Any())
            {
                return(Json(new List <IncidentReportObject>(), JsonRequestBehavior.AllowGet));
            }

            var jsonResult = Json(incidentList, JsonRequestBehavior.AllowGet);

            jsonResult.MaxJsonLength = int.MaxValue;
            return(jsonResult);
        }
        private List <IncidentQuery> GetIncidentQueries()
        {
            var previousQueries = new IncidentQueryBuilderServices().GetAllOrderedIncidentQueries() ?? new List <IncidentQuery>();

            if (!previousQueries.Any())
            {
                return(new List <IncidentQuery>());
            }
            return(previousQueries);
        }
        public ActionResult IsIncidentQueryExisting()
        {
            var genVal = new GenericValidator();

            try
            {
                if (Session["_successfulIncidentQuery"] == null)
                {
                    genVal.Code = -1;
                    return(Json(genVal, JsonRequestBehavior.AllowGet));
                }

                var queryBuilder = Session["_successfulIncidentQuery"] as IncidentQuery;

                if (queryBuilder == null)
                {
                    genVal.Code = -1;
                    return(Json(genVal, JsonRequestBehavior.AllowGet));
                }

                var k = new IncidentQueryBuilderServices().IsIncidentQueryExisting(queryBuilder);
                if (k)
                {
                    genVal.Code = 5;
                    return(Json(genVal, JsonRequestBehavior.AllowGet));
                }


                if (Roles.IsUserInRole("Admin"))
                {
                    genVal.Code = -5;
                }
                else
                {
                    genVal.Code = -2;
                }
                return(Json(genVal, JsonRequestBehavior.AllowGet));
            }
            catch (Exception)
            {
                genVal.Code = 0;
                return(Json(genVal, JsonRequestBehavior.AllowGet));
            }
        }
        public ActionResult SaveSuccessfulQuery(string queryName)
        {
            var genVal = new GenericValidator();

            try
            {
                if (string.IsNullOrEmpty(queryName))
                {
                    genVal.Error = "Please supply all required incidents and try again";
                    genVal.Code  = -1;
                    return(Json(genVal, JsonRequestBehavior.AllowGet));
                }

                if (Session["_successfulIncidentQuery"] == null)
                {
                    genVal.Error = "Session has expired";
                    genVal.Code  = -1;
                    return(Json(genVal, JsonRequestBehavior.AllowGet));
                }

                var queryBuilder = Session["_successfulIncidentQuery"] as IncidentQuery;

                if (queryBuilder == null)
                {
                    genVal.Error = "Session has expired";
                    genVal.Code  = -1;
                    return(Json(genVal, JsonRequestBehavior.AllowGet));
                }

                queryBuilder.IncidentQueryName = queryName.Trim();

                var k = new IncidentQueryBuilderServices().AddIncidentQueryCheckDuplicate(queryBuilder);
                if (k < 1)
                {
                    if (k == -3)
                    {
                        genVal.Error = "Query already exists";
                        genVal.Code  = -3;
                        return(Json(genVal, JsonRequestBehavior.AllowGet));
                    }
                    if (k == -4)
                    {
                        genVal.Error = "Query Name already exists. Please provide a different one";
                        genVal.Code  = -3;
                        return(Json(genVal, JsonRequestBehavior.AllowGet));
                    }

                    genVal.Error = "Process Failed! Please contact the Admin or try again later";
                    genVal.Code  = 0;
                    return(Json(genVal, JsonRequestBehavior.AllowGet));
                }

                genVal.Error = "Query was successfully saved";
                genVal.Code  = (int)k;
                return(Json(genVal, JsonRequestBehavior.AllowGet));
            }
            catch (Exception)
            {
                //ErrorManager.LogApplicationError(ex.StackTrace, ex.Source, ex.Message);
                genVal.Error = "An unknown error was encountered. Query could not be saved. Please try again.";
                genVal.Code  = 0;
                return(Json(genVal, JsonRequestBehavior.AllowGet));
            }
        }