public JsonResult AddEligibleAgency(string plan, int agencyId)
        {
            LoadSession();

            var jsr = new JsonServerResponse();
            jsr.Error = _rtpRepository.AddAgencyToTimePeriod(plan, agencyId, CurrentSessionApplicationState.CurrentProgram);
            return Json(jsr);
        }
        public JsonResult DropEligibleAgency(string plan, int agencyId)
        {
            LoadSession();

            var jsr = new JsonServerResponse();
            jsr.Error = _rtpRepository.DropAgencyFromTimePeriod(plan, agencyId, CurrentSessionApplicationState.CurrentProgram);
            if (!jsr.Error.Equals(""))
            {
                jsr.Error = "That agency sponsors projects in the current Plan. They can not be removed.";
            }
            return Json(jsr);
        }
 public JsonResult AddCycle(string plan, int cycleId)
 {
     var jsr = new JsonServerResponse();
     jsr.Error = _rtpRepository.AddCycleToTimePeriod(plan, cycleId);
     return Json(jsr);
 }
 public JsonResult GetPlanReportGroupingCategoryDetails(int id)
 {
     try
     {
         var result = _rtpProjectRepository.GetPlanReportGroupingCategoryDetails(id);
         return Json(result);
     }
     catch (Exception ex)
     {
         JsonServerResponse jsr = new JsonServerResponse();
         jsr.Error = ex.Message;
         return Json(jsr);
     }
 }
        public JsonResult AddEligibleFundingResource(string timePeriod, int fundingResourceId)
        {
            LoadSessionData();

            var jsr = new JsonServerResponse();
            jsr.Error = _surveyRepository.AddFundingResourceToTimePeriod(_surveyRepository.GetYearId(timePeriod, DRCOG.Domain.Enums.TimePeriodType.Survey), fundingResourceId);
            return Json(jsr);
        }
        /// <summary>
        /// Error handler, returning a JsonServerResponse2 object within a JsonResult object.
        /// </summary>
        /// <param name="errorLogged">if set to <c>true</c> [error logged].</param>
        /// <param name="clientErrorMessage">The client error message.</param>
        /// <param name="includeBoilerPlateMessage">if set to <c>true</c> [include boiler plate message].</param>
        /// <returns></returns>
        protected JsonResult HandleErrorJson(bool errorLogged, string clientErrorMessage, bool includeBoilerPlateMessage)
        {
            JsonServerResponse response = new JsonServerResponse();
            string boilerPlateMsg = "We're sorry, an unexpected error has occurred while attempting to process your request.";
            string errorLogMsg = "The error has been logged.";

            StringBuilder sb = new StringBuilder();
            if (!string.IsNullOrEmpty(clientErrorMessage))
            {
                sb.AppendLine(clientErrorMessage.Trim());
            }
            if (includeBoilerPlateMessage)
            {
                sb.AppendLine(boilerPlateMsg);
            }
            if (errorLogged)
            {
                sb.AppendLine(errorLogMsg);
            }

            response.Error = sb.ToString();

            return Json(response, this.JsonResultContentType);
        }
 public JsonResult AddCurrent2Agency(string tipYear, int projectVersionID, int agencyId)
 {
     var jsr = new JsonServerResponse();
     jsr.Error = _rtpProjectRepository.AddAgencyToTIPProject(projectVersionID, agencyId, false);
     return Json(jsr);
 }
 public JsonResult CreateProject(string projectName, string facilityName, string tipYear, int sponsorOrganizationId, int amendmentTypeId)
 {
     JsonServerResponse jsr = new JsonServerResponse();
     int projectVersionId = 0;
     try
     {
         projectVersionId = _tipRepository.CreateProject(projectName, facilityName, tipYear, sponsorOrganizationId, amendmentTypeId);
     }
     catch (Exception ex)
     {
         jsr.Error = "An error occured creating the TIP";
         return Json(jsr);
     }
     return Json(projectVersionId);
 }
        public JsonResult CreateTip(int startYear, int endYear, int offset)
        {
            JsonServerResponse jsr = new JsonServerResponse();
            string newTipYear = startYear.ToString() + "-" + endYear.ToString();
            try
            {
                _tipRepository.CreateTip(newTipYear, offset);
                jsr.Data = true;
            }
            catch (Exception ex)
            {
                jsr.Error = "An error occured creating the TIP";
                //_logService.Warn("Create new TIP failed for TipYear='" + newTipYear + "'");
            }

            return Json(jsr);
        }
        public JsonResult DropEligibleImprovementType(string timePeriod, int improvementTypeId)
        {
            LoadSessionData();

            var jsr = new JsonServerResponse();
            jsr.Error = _surveyRepository.DropImprovementTypeFromTimePeriod(timePeriod, improvementTypeId, DRCOG.Domain.Enums.ApplicationState.Survey) ? "" : "The improvementType is used in the current Survey. It can not be removed.";
            //if (!jsr.Error.Equals(""))
            //{
            //    jsr.Error = "The improvementType is used in the current Survey. It can not be removed.";
            //}
            return Json(jsr);
        }
 public JsonResult UpdateAgencies(string tipYear, List<int> added, List<int> removed)
 {
     if (added == null)
     {
         added = new List<int>();
     }
     if (removed == null)
     {
         removed = new List<int>();
     }
     //Send the two lists of ID's to the Repo
     try
     {
         _tipRepository.UpdateEligibleAgencies(tipYear, added, removed);
         JsonServerResponse jsr = new JsonServerResponse();
         jsr.Data = true;
         return Json(jsr);
     }
     catch (Exception ex)
     {
         JsonServerResponse jsr = new JsonServerResponse();
         jsr.Error = ex.Message;
         return Json(jsr);
     }
 }
        public JsonResult DropEligibleFundingResource(string timePeriod, int fundingResourceId)
        {
            LoadSessionData();

            var jsr = new JsonServerResponse();
            jsr.Error = _surveyRepository.DropFundingResourceFromTimePeriod(_surveyRepository.GetYearId(timePeriod, DRCOG.Domain.Enums.TimePeriodType.Survey), fundingResourceId, DRCOG.Domain.Enums.ApplicationState.Survey) ? "" : "The funding resource is used in the current Survey. It can not be removed.";
            return Json(jsr);
        }
        public JsonResult DropEligibleAgency(string timePeriod, int agencyId)
        {
            LoadSessionData();

            var jsr = new JsonServerResponse();
            jsr.Error = _surveyRepository.DropAgencyFromTimePeriod(timePeriod, agencyId, DRCOG.Domain.Enums.ApplicationState.Survey);
            if (!jsr.Error.Equals(""))
            {
                jsr.Error = "That agency sponsors projects in the current Survey. They can not be removed.";
            }
            return Json(jsr);
        }
        public JsonResult AddEligibleImprovementType(string timePeriod, int improvementTypeId)
        {
            LoadSessionData();

            var jsr = new JsonServerResponse();
            jsr.Error = _surveyRepository.AddImprovementTypeToTimePeriod(timePeriod, improvementTypeId, DRCOG.Domain.Enums.ApplicationState.Survey);
            return Json(jsr);
        }
 /// <summary>
 /// Gets ProjectTypeId from ImprovementTypeId
 /// </summary>
 /// <param name="guid"></param>
 /// <returns></returns>
 protected JsonResult GetImprovementTypeMatch(int id, ITransportationRepository repo)
 {
     IList<SqlParameter> sqlParms = new List<SqlParameter>();
     sqlParms.Add(new SqlParameter() { SqlDbType = SqlDbType.Int, ParameterName = "@Id", Value = id });
     try
     {
         //var result = RtpProjectRepository.GetLookupSingle<String>("dbo.Lookup_GetProjectTypeByImprovementTypeId", "Value", sqlParms);
         var result = repo.GetLookupCollection("dbo.Lookup_GetProjectTypeByImprovementTypeId", "Id", "Value", sqlParms);
         return Json(new { id = result.First().Key, value = result.First().Value });
     }
     catch (Exception ex)
     {
         JsonServerResponse jsr = new JsonServerResponse();
         jsr.Error = ex.Message;
         return Json(jsr);
     }
 }
 public JsonResult DropEligibleAgency(string tipYear, int agencyId)
 {
     var jsr = new JsonServerResponse();
     jsr.Error = _tipRepository.DropAgencyFromTimePeriod(tipYear, agencyId, Enums.ApplicationState.TIP);
     //TODO: Translate this to make sure it is not a SQL Error. Do this or handle it client side?
     if (!jsr.Error.Equals(""))
     {
         jsr.Error = "That agency sponsors projects in the current TIP. They can not be removed.";
     }
     return Json(jsr);
 }
        /// <summary>
        /// Gets ImprovementTypeId from ProjectTypeId
        /// </summary>
        /// <param name="guid"></param>
        /// <returns></returns>
        protected JsonResult GetProjectTypeMatch(int id, ITransportationRepository repo)
        {
            var result = new List<SelectListItem>();

            IList<SqlParameter> sqlParms = new List<SqlParameter>();
            sqlParms.Add(new SqlParameter("@Id", id));
            try
            {
                var items = repo.GetLookupCollection("[dbo].[Lookup_GetImprovementTypesByProjectId]", "Id", "Value", sqlParms);
                items.ToList().ForEach(x => { result.Add(new SelectListItem { Text = x.Value, Value = x.Key.ToString() }); });
                return Json(new { data = result });
            }
            catch (Exception ex)
            {
                JsonServerResponse jsr = new JsonServerResponse();
                jsr.Error = ex.Message;
                return Json(jsr);
            }
        }
 public JsonResult AddEligibleAgency(string tipYear, int agencyId)
 {
     var jsr = new JsonServerResponse();
     jsr.Error = _tipRepository.AddAgencyToTimePeriod(tipYear, agencyId, Enums.ApplicationState.TIP);
     return Json(jsr);
 }
        /// <summary>
        /// Session timeout error handler, returning a JsonServerResponse2 object within a JsonResult object.
        /// </summary>
        /// <param name="includeBoilerPlateMessage">if set to <c>true</c> [include boiler plate message].</param>
        /// <returns></returns>
        protected JsonResult HandleSessionTimeoutErrorJson(bool includeBoilerPlateMessage)
        {
            JsonServerResponse response = new JsonServerResponse();
            string boilerPlateMsg = "Your session has expired. You must log into the application again.";

            StringBuilder sb = new StringBuilder();
            if (includeBoilerPlateMessage)
            {
                sb.AppendLine(boilerPlateMsg);
            }
            response.Error = sb.ToString();
            response.SessionError = true;

            return Json(response, this.JsonResultContentType);
        }
 public JsonResult CreateProject(string projectName, string facilityName, string plan, int sponsorOrganizationId, int? cycleId)
 {
     JsonServerResponse jsr = new JsonServerResponse();
     int projectVersionId = 0;
     try
     {
         projectVersionId = _rtpRepository.CreateProject(projectName, facilityName, plan, sponsorOrganizationId, cycleId);
     }
     catch (Exception ex)
     {
         jsr.Error = "An error occured creating the RTP Project";
         //_logService.Warn("Create new TIP Project failed for ProjectName='" + projectName + "'");
         return Json(jsr);
     }
     return new JsonResult
     {
         Data = projectVersionId
     };
 }
 public JsonResult DropCurrent2Agency(string tipYear, int projectVersionID, int agencyId)
 {
     var jsr = new JsonServerResponse();
     jsr.Error = _rtpProjectRepository.DropAgencyFromTIP(projectVersionID, agencyId);
     return Json(jsr);
 }
        public JsonResult DropCycle(int cycleId)
        {
            LoadSession();

            var jsr = new JsonServerResponse();
            jsr.Error = _rtpRepository.RemoveCycleFromTimePeriod(cycleId);
            if (!jsr.Error.Equals(""))
            {
                jsr.Error = "Cycle is in use in the current Plan. It can not be removed.";
            }
            return Json(jsr);
        }
 public JsonResult UpdateAgencies(string projectVersionID, List<int> added, List<int> removed)
 {
     if (added == null)
     {
         added = new List<int>();
     }
     if (removed == null)
     {
         removed = new List<int>();
     }
     //Send the two lists of ID's to the Repo
     try
     {
         _rtpProjectRepository.UpdateCurrentSponsors(projectVersionID, added, removed);
         JsonServerResponse jsr = new JsonServerResponse();
         jsr.Data = true;
         return Json(jsr);
     }
     catch (Exception ex)
     {
         JsonServerResponse jsr = new JsonServerResponse();
         jsr.Error = ex.Message;
         return Json(jsr);
     }
 }
        public JsonResult AddEligibleAgency(string timePeriod, int agencyId)
        {
            LoadSessionData();

            var jsr = new JsonServerResponse();
            jsr.Error = _surveyRepository.AddAgencyToTimePeriod(timePeriod, agencyId, DRCOG.Domain.Enums.ApplicationState.Survey);
            return Json(jsr);
        }