public ActionResult Dashboard(string year, string listType, bool? showAll)
        {
            LoadSessionData();

            //if (String.IsNullOrEmpty(year))
            //{
            //    year = _surveyRepository.GetCurrentRtpPlanYear();
            //    return RedirectToAction("Dashboard", new { @year = year });
            //}
            CurrentSessionApplicationState.CurrentSurvey = year;

            CurrentSessionApplicationState.CurrentUser.HasProjects = UserService.CheckPersonHasProjects(CurrentSessionApplicationState.CurrentUser, _surveyRepository.GetYearId(year, DRCOG.Domain.Enums.TimePeriodType.Survey));

            //if (appstate.CurrentUser.profile.PersonID.Equals(default(int)))
            //{
            //    UserService.LoadPerson(appstate.CurrentUser.profile);
            //}
            //Sets the default of the Dashboard type. I will set it to Sponsor.
            var dashboardListType =
                String.IsNullOrEmpty(listType)
                ?
                (
                    CurrentSessionApplicationState.CurrentUser.IsInRole("Survey Administrator") || CurrentSessionApplicationState.CurrentUser.IsInRole("Administrator")
                    ? DRCOG.Domain.Enums.SurveyDashboardListType.Sponsor
                    : (Request.IsAuthenticated ? DRCOG.Domain.Enums.SurveyDashboardListType.MyProjects : DRCOG.Domain.Enums.SurveyDashboardListType.Sponsor)
                )
                : (DRCOG.Domain.Enums.SurveyDashboardListType)Enum.Parse(typeof(DRCOG.Domain.Enums.SurveyDashboardListType), listType, true);

            DashboardViewModel viewModel = new DashboardViewModel()
            {
                Year = year,
                ListType = dashboardListType,
                Person = CurrentSessionApplicationState.CurrentUser
            };

            //Handle ShowAll bit
            viewModel.ShowAll = (showAll ?? false);

            // get the view model from the repo
            viewModel = _surveyRepository.GetDashboardViewModel(viewModel /*year, dashboardListType*/);

            if (viewModel.Person.HasProjects)
            {
                viewModel.Current.AgencyProjectList = _surveyRepository.GetProjects(this.ValidateSearchData(new SearchModel() { SponsorContactId = CurrentSessionApplicationState.CurrentUser.profile.PersonID, Year = year, ShowAllForAgency = true }, StringEnum.GetStringValue(CurrentSessionApplicationState.CurrentProgram)));

                // TODO: shouldn't the data from the database be accurate?
            #if bozo
                CurrentSessionApplicationState.CurrentUser.SponsoredProjectVersionIds.Clear();
                foreach (var project in viewModel.Current.AgencyProjectList)
                {
                    CurrentSessionApplicationState.CurrentUser.SponsoredProjectVersionIds.Add(project.ProjectVersionId);
                }
            #endif
                int index = viewModel.Current.AgencyProjectList.FindIndex(FindIncompleteUpdateStatus);
                if (index >= 0 && viewModel.Current.AgencyProjectList.Count > 0)
                {
                    viewModel.Current.ShowCertification = false;
                }
                else
                {
                    viewModel.Current.ShowCertification = true;
                    foreach (Project p in viewModel.Current.AgencyProjectList)
                    {
                        p.Funding = _surveyRepository.GetFunding(p.ProjectVersionId, p.TimePeriod);
                    }
                }
            }

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

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

            // TODO: the following line can/should be set in the repo
            //viewModel.ListType = dashboardListType;

            var pp = CreatePageParameters();
            pp.Add("SurveyYear", viewModel.Year);
            pp.Add("SurveyId", viewModel.Current.Id);
            pp.Add("SurveyName", viewModel.Current.Name);
            SetPageParameters(pp);

            return View(viewModel);
        }
        public DashboardViewModel GetDashboardViewModel(DashboardViewModel model /* string year, Enums.SurveyDashboardListType type */)
        {
            //DashboardViewModel model = new DashboardViewModel();
            //RtpSummary rtpSummary = GetSummary(financialYear);

            //We call different sprocs based on the Enum
            string sprocName = null;
            List<SqlParameter> sqlParams = new List<SqlParameter>();
            sqlParams.Add(new SqlParameter("@Year", model.Year));

            bool hasItemDate = false;

            //if ((model.ShowAll != null) && (model.ShowAll.Equals("true"))) sqlParams.Add(new SqlParameter("@ShowAll", 1));
            //int versionStatusId = rtpSummary.IsAmendable() ? (int)Enums.RTPVersionStatus.Pending : (int)Enums.RTPVersionStatus.Active;
            switch (model.ListType)
            {
                case DRCOG.Domain.Enums.SurveyDashboardListType.MyProjects:
                    sprocName = "[Survey].[GetDashboardListByMyProjects]";
                    sqlParams.Add(new SqlParameter("@PersonGuid", model.Person.profile.PersonGUID));
                    break;
                case DRCOG.Domain.Enums.SurveyDashboardListType.ProjectType:
                    sprocName = "[Survey].[GetDashboardListByProjectType]";
                    break;
                case DRCOG.Domain.Enums.SurveyDashboardListType.Sponsor:
                    sprocName = "[Survey].[GetDashboardListBySponsor2]";
                    if (model.ShowAll)
                    {
                        sqlParams.Add(new SqlParameter("@ShowAll", 1));
                    }
                    hasItemDate = true;
                    break;
                case DRCOG.Domain.Enums.SurveyDashboardListType.UpdateStatus:
                    sprocName = "[Survey].[GetDashboardListByUpdateStatus]";
                    break;
                case DRCOG.Domain.Enums.SurveyDashboardListType.ImprovementType:
                    sprocName = "[Survey].[GetDashboardListByImprovementType]";
                    break;
                //case Enums.SurveyDashboardListType.SponsorWithTipid:
                //    sprocName = "[Survey].[GetDashboardListWithTipId]";
                //    break;
                default:
                    throw new NotImplementedException("Not a valid SurveyDashboardListType");
            }

            SqlCommand cmd = new SqlCommand(sprocName);
            cmd.CommandType = CommandType.StoredProcedure;
            foreach(SqlParameter p in sqlParams)
            {
                cmd.Parameters.Add(p);
            }

            //cmd.Parameters.AddWithValue("@Year", model.Year);

            //cmd.Parameters.AddWithValue("@VersionStatusId", versionStatusId); // removed not sure if we need this.
            //if (!rtpSummary.IsPending) cmd.Parameters.AddWithValue("@IsActive", 1);

            model.Current = this.GetSurvey(model.Year);
            if (model.Current == null)
            {
                Logger.Debug("No Survey found for " + model.Year);
                model.Current = new Survey();
            }

            using (IDataReader rdr = this.ExecuteReader(cmd))
            {
                int ccol = rdr.GetOrdinal("Count");
                int ocol = rdr.GetOrdinal("ItemName");
                int dcol = hasItemDate ? rdr.GetOrdinal("ItemDate") : -1;
                while (rdr.Read())
                {
                    model.DashboardItems.Add(new DashboardListItem()
                    {
                        count = rdr.GetInt32(ccol),
                        ItemName = rdr.GetString(ocol),
                        ItemDate = TryGetDateTime(rdr, dcol)
                    });
                }
            }

            //model.RtpStatus.IsCurrent = financialYear == GetCurrentRtpPlanYear();
            //model.RtpSummary = rtpSummary;

            return model;
        }