private void PopulateAgenciesForState(string StateFIPS) { var Agencies = LookupBLL.GetAgenciesForState(StateFIPS, true); if (Agencies != null) { IEnumerable <KeyValuePair <int, string> > OrderedAgencies = Agencies.OrderBy(p => p.Value); ddlAgency.DataSource = OrderedAgencies; } else { ddlAgency.DataSource = Agencies; } ddlAgency.DataTextField = "Value"; ddlAgency.DataValueField = "Key"; ddlAgency.DataBind(); if (ddlAgency.Items.Count > 0) { ddlAgency.Items.Insert(0, new ListItem("<-- Select agency -->", "0")); btnSubmit.Enabled = true; } else { ddlAgency.Items.Add(new ListItem("No agencies available", "0")); btnSubmit.Enabled = false; } }
private void HandleAgencyDisplayLogic(string StateFIPS) { plhAgencies.Visible = true; ddlAgency.DataSource = LookupBLL.GetAgenciesForState(StateFIPS); ddlAgency.DataTextField = "Value"; ddlAgency.DataValueField = "Key"; ddlAgency.DataBind(); ddlAgency.Items.Insert(0, new ListItem("Select an Agency", "0")); }
private void HandleAgencyDisplayLogic(string StateFIPS) { plhAgencies.Visible = true; if (this.AccountInfo.Scope != Scope.Agency) { ddlAgency.DataSource = LookupBLL.GetAgenciesForState(StateFIPS); ddlAgency.DataTextField = "Value"; ddlAgency.DataValueField = "Key"; ddlAgency.DataBind(); } else { PopulateAgenciesForUser(); } if (ddlAgency.Items.Count > 1) { ddlAgency.Items.Insert(0, new ListItem("Select Agency", "0")); } }
private void HandleAgencyDisplayLogic(string StateFIPS) { plhAgencies.Visible = true; if (this.AccountInfo.Scope.IsHigherOrEqualTo(Scope.State)) { var Agencies = LookupBLL.GetAgenciesForState(StateFIPS); if (Agencies != null) { IEnumerable <KeyValuePair <int, string> > OrderedAgencies = Agencies.OrderBy(p => p.Value); ddlAgency.DataSource = OrderedAgencies; } else { ddlAgency.DataSource = Agencies; } ddlAgency.DataTextField = "Value"; ddlAgency.DataValueField = "Key"; ddlAgency.DataBind(); if (ddlAgency.Items.Count > 1) { ddlAgency.Items.Insert(0, new ListItem("-- Select agency --", "0")); } else { ddlAgency.Items.Add(new ListItem("No agencies available", "0")); } } else if (this.AccountInfo.Scope.IsEqual(Scope.SubStateRegion)) { PopulateAgenciesForSubStateUser(); } else { PopulateAgenciesForUser(); } }
protected void PopulateAgencyList() { List <KeyValuePair <int, string> > AgencyListObj = new List <KeyValuePair <int, string> >(); //All Agencies where User is Admin. IEnumerable <UserRegionalAccessProfile> AgenciesWhereUserIsAdmin = null; IDictionary <int, string> AllAgenciesInState = LookupBLL.GetAgenciesForState(UserData.StateFIPS); if (IsCreatorAgencyScope) { AgenciesWhereUserIsAdmin = UserAgencyBLL.GetUserAgencyProfiles(this.AccountInfo.UserId, true); KeyValuePair <int, string>?matchingAgency = null; //get KeyValue Pair of all agencies in state where the Creator[the person who is adding the User] is Admin foreach (UserRegionalAccessProfile AgencyAdminProfile in AgenciesWhereUserIsAdmin) { matchingAgency = AllAgenciesInState.Where(p => p.Key == AgencyAdminProfile.RegionId).FirstOrDefault(); if (matchingAgency.HasValue) { AgencyListObj.Add(matchingAgency.Value); matchingAgency = null; } } } else if (IsCreatorSubStateScope) { IEnumerable <UserRegionalAccessProfile> SubStatesWhereUserIsAdmin = UserSubStateRegionBLL.GetUserSubStateRegionalProfiles(this.AccountInfo.UserId, true); if (SubStatesWhereUserIsAdmin != null && SubStatesWhereUserIsAdmin.Count() > 0) { //Collect Agencies that are part of Creator's Sub State regions. foreach (UserRegionalAccessProfile subStateprofile in SubStatesWhereUserIsAdmin) { //Get Agencies for substate IEnumerable <ShiptalkLogic.BusinessObjects.Agency> agencyProfiles = LookupBLL.GetAgenciesForSubStateRegion(subStateprofile.RegionId); if (agencyProfiles != null && agencyProfiles.Count() > 0) { AgencyListObj.AddRange(agencyProfiles.Select(p => new KeyValuePair <int, string>(p.Id.Value, p.Name))); } } } } else { AgencyListObj = AllAgenciesInState.ToList <KeyValuePair <int, string> >(); } //Before we return the list of Agencies we need to remove the Agencies that the User is already assigned to, //so that the user is not added to the same Agency again. if (AgencyListObj != null && AgencyListObj.Count > 0) { IEnumerable <UserRegionalAccessProfile> ExistingAgencies = null; ExistingAgencies = UserAgencyBLL.GetUserAgencyProfiles(UserProfileUserId, false); if (ExistingAgencies != null && ExistingAgencies.Count() > 0) { KeyValuePair <int, string>?existAgency = null; foreach (UserRegionalAccessProfile ExistingAgency in ExistingAgencies) { existAgency = AgencyListObj.Where(p => p.Key == ExistingAgency.RegionId).FirstOrDefault(); if (existAgency.HasValue) { AgencyListObj.Remove(existAgency.Value); existAgency = null; } } } } this.AgencyList = AgencyListObj; }