Esempio n. 1
0
        private SearchModel ValidateSearchData(SearchModel projectSearchModel, string currentProgram)
        {
            //Check completeness of Year
            if ((projectSearchModel.YearId.Equals(default(int)) && (!String.IsNullOrEmpty(projectSearchModel.Year))))
            {
                //Lookup the YearID
                projectSearchModel.YearId = _surveyRepository.GetYearId(projectSearchModel.Year, DRCOG.Domain.Enums.TimePeriodType.Survey);
            }

            if ((!projectSearchModel.YearId.Equals(default(int)) && (String.IsNullOrEmpty(projectSearchModel.Year))))
            {
                //Lookup the Year
                projectSearchModel.Year = _surveyRepository.GetYear((int)projectSearchModel.YearId);
            }

            //if(!projectSearchModel.SponsorContactId.Equals(default(int)))
            //{
            //    projectSearchModel.SponsorAgencyID = _surveyRepository.GetSpon
            //}

            //Check completeness of SponsorAgency
            if ((projectSearchModel.SponsorAgencyID == null) && (projectSearchModel.SponsorAgency != null))
            {
                //Lookup the SponsorAgencyID
                projectSearchModel.SponsorAgencyID = _surveyRepository.GetSponsorAgencyID(projectSearchModel.SponsorAgency);
            }

            if ((projectSearchModel.SponsorAgencyID != null) && (projectSearchModel.SponsorAgency == null))
            {
                //Lookup the SponsorAgency
                projectSearchModel.SponsorAgency = _surveyRepository.GetSponsorAgency(projectSearchModel.SponsorAgencyID);
            }

            string statusType = "";
            switch (currentProgram)
            {
                case "Transportation Improvement Plan":
                    statusType = "TIP Amendment Status";
                    break;
                case "Regional Transportation Plan":
                    statusType = "RTP Amendment Status";
                    break;
                case "Transportation Improvement Survey":
                    statusType = "Survey Amendment Status";
                    break;
                default:
                    statusType = "Survey Amendment Status"; // If something goes wrong, assume Survey
                    break;
            }

            //Check completeness of AmendmentStatus
            if ((projectSearchModel.AmendmentStatusID == null) && (projectSearchModel.AmendmentStatus != null))
            {
                //Lookup the AmendmentStatusID
                projectSearchModel.AmendmentStatusID = _surveyRepository.GetStatusID(projectSearchModel.AmendmentStatus, statusType);
            }

            if ((projectSearchModel.AmendmentStatusID != null) && (projectSearchModel.AmendmentStatus == null))
            {
                //Lookup the AmendmentStatus
                projectSearchModel.AmendmentStatus = _surveyRepository.GetStatus(projectSearchModel.AmendmentStatusID, statusType);
            }

            //Check completeness of ImprovementType
            if ((projectSearchModel.ImprovementTypeID == null) && (projectSearchModel.ImprovementType != null))
            {
                //Lookup the ImprovementTypeID
                projectSearchModel.ImprovementTypeID = _surveyRepository.GetImprovementTypeID(projectSearchModel.ImprovementType);
            }

            if ((projectSearchModel.ImprovementTypeID != null) && (projectSearchModel.ImprovementType == null))
            {
                //Lookup the ImprovementType
                projectSearchModel.ImprovementType = _surveyRepository.GetImprovementType(projectSearchModel.ImprovementTypeID);
            }

            //Check completeness of ProjectType
            if ((projectSearchModel.ProjectTypeID == null) && (projectSearchModel.ProjectType != null))
            {
                //Lookup the ProjectTypeID
                projectSearchModel.ProjectTypeID = _surveyRepository.GetProjectTypeID(projectSearchModel.ProjectType);
            }

            if ((projectSearchModel.ProjectTypeID != null) && (projectSearchModel.ProjectType == null))
            {
                //Lookup the ProjectType
                projectSearchModel.ProjectType = _surveyRepository.GetProjectType(projectSearchModel.ProjectTypeID);
            }

            return projectSearchModel;
        }
Esempio n. 2
0
        public ActionResult ProjectList(string year, string dft, string df, int? page)
        {
            LoadSessionData();
            //if (String.IsNullOrEmpty(year))
            //{
            //    year = _surveyRepository.GetCurrentRtpPlanYear();
            //    return RedirectToAction("Dashboard", new { @year = year });
            //}
            //Make a ProjectViewModel object from the search criteria
            var projectSearchModel = new SearchModel();
            Survey survey = _surveyRepository.GetSurvey(year);

            //If there is a 'df' dashboard filter, then the Session search criteria are reset.
            if (df != null)
            {
                //Reset Session search criteria
                CurrentSessionApplicationState.ProjectSearchModel = null;

                //Assign dashboard search filter criteria
                projectSearchModel.Year = year;

                //ToDo: convert 'df' we need to know what DashboardListType ('dft') it is (Sponsor = 1,ProjectType = 2,AmendmentStatus = 3)
                //ToDo: Assign the 'df' variable to projectSearchModel
                switch (dft)
                {
                    case "AmendmentStatus":
                        projectSearchModel.AmendmentStatus = df;
                        break;
                    case "Sponsor":
                        projectSearchModel.SponsorAgency = df;
                        break;
                    case "ProjectType":
                        projectSearchModel.ProjectType = df;
                        break;
                    case "ImprovementType":
                        projectSearchModel.ImprovementType = df;
                        break;
                    case "MyProjects":
                        projectSearchModel.SponsorAgency = df;
                        projectSearchModel.SponsorContactId = CurrentSessionApplicationState.CurrentUser.profile.PersonID;
                        break;
                }

                //Assume from dashboard that we only want active projects.
                //projectSearchModel.VersionStatusId = rtpSummary.IsPending ? (int)RTPVersionStatus.Pending : (int)RTPVersionStatus.Active;
            }
            else
            {
                if (dft != null)
                {
                    switch (dft)
                    {
                        case "AmendmentStatus":
                            projectSearchModel.AmendmentStatus = df;
                            break;
                        case "Sponsor":
                            projectSearchModel.SponsorAgency = df;
                            break;
                        case "ProjectType":
                            projectSearchModel.ProjectType = df;
                            break;
                        case "ImprovementType":
                            projectSearchModel.ImprovementType = df;
                            break;
                        case "MyProjects":
                            projectSearchModel.SponsorAgency = df;
                            //projectSearchModel.SponsorContactId = appstate.CurrentUser.profile.PersonID;
                            projectSearchModel.ShowMySponsorAgencies = true;
                            projectSearchModel.ShowAllForAgency = true;
                            projectSearchModel.Profile = CurrentSessionApplicationState.CurrentUser.profile;
                            break;
                    }
                }
                //Check to see if there is a projectSearchModel in Session. If not, then we have nt selected a dashboard or project search tab option.
                if ((CurrentSessionApplicationState.ProjectSearchModel as SearchModel) != null)
                {
                    //Pull ProjectSearchModel from session and use
                    projectSearchModel = (SearchModel)CurrentSessionApplicationState.ProjectSearchModel;
                }
                else
                {
                    //Create search using RTPYear and Active Version only (default).
                    projectSearchModel.Year = year;
                    //projectSearchModel.VersionStatusId = rtpSummary.IsPending ? (int)RTPVersionStatus.Pending : (int)RTPVersionStatus.Active;
                }
                projectSearchModel.Year = year;
                projectSearchModel.ShowAllForAgency = true;
            }

            //Before passing the ProjectSearchModel, make sure it is validated
            projectSearchModel = this.ValidateSearchData((SearchModel)projectSearchModel, StringEnum.GetStringValue(CurrentSessionApplicationState.CurrentProgram));

            //DTS NOTE: We don't fetch the model from the Repo directly because we will have to handle some complex criteria and filtering options
            var viewModel = new ProjectListViewModel();
            viewModel.Current = survey;
            //viewModel.RtpSummary.RtpYear = year;
            viewModel.ProjectList = _surveyRepository.GetProjects(projectSearchModel);

            viewModel.ListCriteria = df;
            viewModel.ListType = dft;
            if (viewModel.ProjectList.Count > 1000)
            {
                int originalCount = viewModel.ProjectList.Count;
                viewModel.ProjectList = viewModel.ProjectList.Take(1000).ToList();
                ViewData["ShowMessage"] = "Your results exceeded 1000 records. Please refine your search to narrow your results";
            }
            //viewModel.RestorableProjectList = _surveyRepository.GetRestoreProjectList(_surveyRepository.GetYearId(year));
            //Now save this projectSearchModel (for future searchs)
            CurrentSessionApplicationState.ProjectSearchModel = projectSearchModel;

            viewModel.Person = CurrentSessionApplicationState.CurrentUser;

            viewModel.Current.SponsorsOrganization = new SponsorOrganization()
            {
                OrganizationId = viewModel.Person.SponsorOrganizationId
                ,
                OrganizationName = viewModel.Person.SponsorOrganizationName
            };

            if (viewModel.Person.HasProjects || viewModel.Current.IsAdmin())
            {
                if (viewModel.Current.IsAdmin())
                {
                    viewModel.Current.AgencyProjectList = viewModel.ProjectList;
                }
                else
                {
                    viewModel.Current.AgencyProjectList = _surveyRepository.GetProjects(this.ValidateSearchData(new SearchModel() { ShowMySponsorAgencies = true, Year = year, ShowAllForAgency = true, Profile = CurrentSessionApplicationState.CurrentUser.profile }, StringEnum.GetStringValue(CurrentSessionApplicationState.CurrentProgram)));
                }
                int index = viewModel.Current.AgencyProjectList.FindIndex(FindIncompleteUpdateStatus);
                if (index >= 0)
                {
                    viewModel.Current.ShowCertification = false;
                    viewModel.Current.AgencyProjectList = null;
                    // element exists, do what you need
                }
                else
                {
                    viewModel.Current.ShowCertification = true;

                    List<Project> projects = new List<Project>();
                    foreach (Project p in viewModel.Current.AgencyProjectList)
                    {
                        p.Funding = _surveyRepository.GetFunding(p.ProjectVersionId, p.TimePeriod);
                        projects.Add(p);
                        //_surveyRepository.GetSponsorContacts(projects.Add(p));
                    }

                    viewModel.Current.AgencyProjectList = projects;
                    viewModel.Current.AgencySponsorContacts = _surveyRepository.GetContact(new ContactSearch()
                    {
                        ShowAllForAgency = true
                        ,
                        TimePeriodId = projectSearchModel.YearId
                        ,
                        PersonId = CurrentSessionApplicationState.CurrentUser.profile.PersonID
                    });
                }
            }

            viewModel.Current.ProjectSponsorsModel = _surveyRepository.GetProjectSponsorsModel(default(int), year);

            return View(viewModel);
        }
Esempio n. 3
0
        public List<Project> GetProjects(SearchModel projectSearchModel)
        {
            List<Project> list = new List<Project>();

            SqlCommand cmd = new SqlCommand("[Survey].[GetProjects]");
            cmd.CommandType = CommandType.StoredProcedure;

            //I will speed up these queries by restricting the list on three items: TipYear, TipYearID or IsActive. -DBD
            if (!projectSearchModel.Exclude_Year) // If we are excluding a TipYear, then we must return everything (no SQL optimization)
            {
                if (!projectSearchModel.YearId.Equals(default(int))) cmd.Parameters.AddWithValue("@YEARID", projectSearchModel.YearId);
            }
            if (projectSearchModel.VersionStatusId > 0)
            {
                //if ((bool)projectSearchModel.ActiveVersion) cmd.Parameters.AddWithValue("@ISACTIVE", 1);
                cmd.Parameters.AddWithValue("@VersionStatusId", projectSearchModel.VersionStatusId);
                //else cmd.Parameters.AddWithValue("@ISACTIVE", 0);
            }
            if (!projectSearchModel.SponsorContactId.Equals(default(int)))
            {
                cmd.Parameters.AddWithValue("@SponsorContactId", projectSearchModel.SponsorContactId);
            }
            if (!projectSearchModel.SponsorAgencyID.Equals(default(int)) || projectSearchModel.SponsorAgencyID.HasValue)
            {
                cmd.Parameters.AddWithValue("@SponsorAgencyId", projectSearchModel.SponsorAgencyID);
            }

            if (projectSearchModel.ShowMySponsorAgencies)
            {
                cmd.Parameters.AddWithValue("@PersonId", projectSearchModel.Profile.PersonID);
            }

            //if (!projectSearchModel.SponsorContactId.Equals(default(int)))
            //{
                cmd.Parameters.AddWithValue("@ShowAllForAgency", projectSearchModel.ShowAllForAgency);
            //}

            using (IDataReader rdr = this.ExecuteReader(cmd))
            {
                while (rdr.Read())
                {
                    Project project = new Project()
                    {
                        ProjectVersionId = rdr["ProjectVersionId"].ToString().SmartParseDefault<int>(default(int))
                        ,
                        SponsorName = rdr["Sponsor"].ToString()
                        ,
                        ProjectId = rdr["ProjectId"].ToString().SmartParseDefault<int>(default(int))
                        ,
                        TimePeriodId = rdr["TimePeriodId"].ToString().SmartParseDefault<int>(default(int))
                        ,
                        TimePeriod = rdr["TimePeriod"].ToString()
                        ,
                        ProjectName = rdr["ProjectName"].ToString()
                        ,
                        COGID = rdr["COGID"].ToString()
                        ,
                        ImprovementType = rdr["ImprovementType"].ToString()
                        ,
                        UpdateStatusId = rdr["UpdateStatusId"].ToString().SmartParseDefault<int>(default(int))
                        ,
                        ReportOnlyOpenDate = rdr["OpenYear"].ToString()
                        ,
                        PreviousVersionId = rdr["PreviousProjectVersionID"].ToString().SmartParseDefault<int>(default(int))
                    };
                    list.Add(project);

                }
            }

            // These are processed via the SQL retrieval code optimization, so only process this one when exclude is checked.
            if ((projectSearchModel.Year != null) && (projectSearchModel.Exclude_Year))
            {
                list = (from fli in list
                        where (projectSearchModel.Year.ToWildcardRegex().IsMatch(fli.TimePeriod))
                        select fli).ToList<Project>();
            }

            //if ((projectSearchModel.VersionStatusId > 0) && (projectSearchModel.Exclude_ActiveVersion))
            //{
            //    list = (from fli in list
            //            where (!fli.VersionStatus.Equals(projectSearchModel.VersionStatus))
            //            select fli).ToList<RtpSummary>();
            //}

            // Set ToUpper to ensure results found. No case sensitive required.
            if (!String.IsNullOrEmpty(projectSearchModel.COGID))
            {
                projectSearchModel.COGID = projectSearchModel.COGID.ToUpper();
            }

            //Now that we have the base data, let's apply the rest of our parameters
            // Trying to list the paramters here by most restrictive first. Should make searches much quicker. -DBD
            if ((projectSearchModel.COGID != null) && (!projectSearchModel.COGID.Equals("")))
            {
                list = (from fli in list
                        where ((projectSearchModel.COGID.ToWildcardRegex().IsMatch(fli.COGID)) && (!projectSearchModel.Exclude_COGID))
                        || ((!projectSearchModel.COGID.ToWildcardRegex().IsMatch(fli.COGID)) && (projectSearchModel.Exclude_COGID))
                        select fli).ToList<Project>();
            }

            if (projectSearchModel.SponsorAgency != null)
            {
                list = (from fli in list
                        where ((fli.SponsorName == projectSearchModel.SponsorAgency) && (!projectSearchModel.Exclude_SponsorAgency))
                        || ((fli.SponsorName != projectSearchModel.SponsorAgency) && (projectSearchModel.Exclude_SponsorAgency))
                        select fli).ToList<Project>();
            }

            //if (projectSearchModel.AmendmentStatus != null)
            //{
            //    list = (from fli in list
            //            where ((fli.AmendmentStatus == projectSearchModel.AmendmentStatus) && (!projectSearchModel.Exclude_AmendmentStatus))
            //            || ((fli.AmendmentStatus != projectSearchModel.AmendmentStatus) && (projectSearchModel.Exclude_AmendmentStatus))
            //            select fli).ToList<RtpSummary>();
            //}

            //if (projectSearchModel.ProjectType != null)
            //{
            //    list = (from fli in list
            //            where ((fli.ProjectType == projectSearchModel.ProjectType) && (!projectSearchModel.Exclude_ProjectType))
            //            || ((fli.ProjectType != projectSearchModel.ProjectType) && (projectSearchModel.Exclude_ProjectType))
            //            select fli).ToList<RtpSummary>();
            //}

            if ((projectSearchModel.ProjectName != null) && (!projectSearchModel.ProjectName.Equals("")))
            {
                list = (from fli in list
                        where ((projectSearchModel.ProjectName.ToWildcardRegex().IsMatch(fli.ProjectName)) && (!projectSearchModel.Exclude_ProjectName))
                        || ((!projectSearchModel.ProjectName.ToWildcardRegex().IsMatch(fli.ProjectName)) && (projectSearchModel.Exclude_ProjectName))
                        select fli).ToList<Project>();
            }

            return list;
        }