Ejemplo n.º 1
0
        private void PopulateAgenciesForUser()
        {
            IEnumerable <UserRegionalAccessProfile> adminProfiles = UserAgencyBLL.GetUserAgencyProfiles(UserId, true);

            if (IsSelectedRoleApproverSpecial)
            {
                adminProfiles = adminProfiles.Where(p => p.IsApproverDesignate == true);
            }

            if (adminProfiles != null)
            {
                adminProfiles = adminProfiles.OrderBy(p => p.RegionName);
            }

            BindRegionalData(adminProfiles, ddlAgency);
            if (adminProfiles == null || adminProfiles.Count() == 0)
            {
                ddlAgency.Items.Add(new ListItem("No agencies available", "0"));
            }
            else if (ddlAgency.Items.Count > 1)
            {
                ddlAgency.Items.Insert(0, new ListItem("-- Select agency --", "0"));
                // ddlRoles.SelectedValue = "0";
            }
        }
Ejemplo n.º 2
0
        private int GetAgencyIdForNewUser()
        {
            string sID = string.Empty;

            if (ddlAgency.Items.Count == 0)
            {
                if (ddlAgency.SelectedValue.Trim() == string.Empty)
                {
                    sID = UserAgencyBLL.GetUserAgencyProfiles(this.AccountInfo.UserId, true).First().RegionId.ToString();
                }

                //throw new ShiptalkException("The Agency must be provided to create a new Agency Level User", false, new ArgumentNullException("AgencyId"));
            }
            else if (ddlAgency.Items.Count == 1)
            {
                sID = ddlAgency.Items[0].Value;
            }
            else
            {
                sID = ddlAgency.SelectedValue.Trim();
            }


            return(int.Parse(sID));
        }
Ejemplo n.º 3
0
        protected void dataSourceAgencyUserAdd_Updated(object sender, ObjectContainerDataSourceStatusEventArgs e)
        {
            UserRegionalAccessProfile ChangedUserAgencyRegionData = (UserRegionalAccessProfile)e.Instance;

            UpdateUserAgencyData(ChangedUserAgencyRegionData);
            if (UserAgencyRegionData.RegionId != 0)
            {
                if (UserAgencyBLL.AddUserAgency(UserAgencyRegionData, this.AccountInfo.UserId))
                {
                    //display success message
                    DisplayMessage("The submitted information has been saved successfully.", false);
                }
                else
                {
                    DisplayMessage("Sorry. We were unable to save the information. Please contact support for assistance.", true);
                }
            }
            else
            {
                plhMessage.Visible   = true;
                lblTitleMessage.Text = "Error";
                lblMessage.Text      = "An agency must be selected.";
                lblMessage.CssClass  = "required";

                hlBackToEdit.EnableViewState = false;
                hlBackToEdit.Visible         = false;
                hlBackToEdit.NavigateUrl     = RouteController.UserEdit(UserProfileUserId);
            }

            Page.DataBind();
        }
Ejemplo n.º 4
0
        private void PopulateAgenciesForUser()
        {
            IEnumerable <UserRegionalAccessProfile> UserAgencies = UserAgencyBLL.GetUserAgencyProfiles(UserId, false);

            if (UserAgencies != null)
            {
                UserAgencies = UserAgencies.Where(p => p.IsActive == true);
            }

            BindUserAgency(UserAgencies);
        }
        protected void dataSourceAgencyUserEdit_Updated(object sender, ObjectContainerDataSourceStatusEventArgs e)
        {
            //UserAgencyData = (UserRegionalAccessProfile)e.Instance;
            UserAgencyData = null;
            SynchronizeChangesToUserAgencyData((UserRegionalAccessProfile)e.Instance);

            //Readonly descriptors verification:
            //  New logic to ensure that certain readonly descriptors are not saved along with non-readonly ones.
            bool   ShowError = true;
            string Message   = "Sorry. We were unable to save the information. Please contact support for assistance.";

            if (ValidateDescriptorsForUser(ref Message))
            {
                if (UserAgencyBLL.UpdateUserAgency(UserAgencyData, this.AccountInfo.UserId))
                {
                    //display success message
                    bool ReviewerUpdateFailed = false;

                    //Save the new ReviewerID (Supervisor)
                    if (NewSupervisorId != UserIdOfOldReviewer)
                    {
                        ReviewerUpdateFailed = !UserBLL.SaveSupervisorForUser(UserAgencyData.UserId, NewSupervisorId, AgencyId, this.AccountInfo.UserId);
                    }

                    if (ReviewerUpdateFailed)
                    {
                        DisplayMessage("The new supervisor was not saved. The rest of the submitted information has been saved successfully.", false);
                        ShowError = false;
                    }
                    else
                    {
                        DisplayMessage("The submitted information has been saved successfully.", false);
                        ShowError = false;
                    }
                }
            }

            //Added error for the readonly descriptors verification
            if (ShowError)
            {
                DisplayMessage(Message, true);
            }
        }
Ejemplo n.º 6
0
 private void PopulateAgenciesForUser()
 {
     BindRegionalData(UserAgencyBLL.GetUserAgencyProfiles(UserId, true), ddlAgency);
 }
Ejemplo n.º 7
0
        private bool IsAuthorized()
        {
            /*  Approval Data Authorization Logic is written as follows:
             *      A: The Approver must be within the same State as the User whose profile is pending approval.
             *      B: The Approver must be an Admin ANDALSO an Approver Designate of Same Scope or Higher scope.
             *      C: If the account pending approval is for State Admin, then the Approver can be be a SHIP director or State Admin with Approver Designate rights.
             *      D: If the Approver is a CMS Level User, the Approver must be a CMS Admin with Approver Designate rights.
             *      E:  Introduced 03/07/2010 - User who is Admin with Descriptor ID 8 [Approver] can approve within A-D rule context.
             */

            //Lets Gather parameters here for verifying the business logic.
            string requestedState = ViewData.StateFIPS;
            Scope  requestedScope = ViewData.Scope;
            bool   IsCMSRegionAccountRequested = ViewData.IsUserCMSRegionalScope;
            bool   IsCMSAccountRequested       = ViewData.IsUserCMSScope;
            bool   IsAdminAccountRequested     = ViewData.IsAdmin;

            string ApproverState           = this.AccountInfo.StateFIPS;
            Scope  ApproverScope           = this.AccountInfo.Scope;
            int    ApproverUserId          = AccountInfo.UserId;
            bool   ApproverIsAdmin         = this.AccountInfo.IsAdmin;
            bool   IsApproverShipDirector  = this.AccountInfo.IsShipDirector;
            bool   IsApproverStateApprover = this.AccountInfo.IsStateAdmin && this.AccountInfo.IsApproverDesignate.HasValue &&
                                             this.AccountInfo.IsApproverDesignate.Value;
            bool IsApproverCMSApprover = this.AccountInfo.IsAdmin && this.AccountInfo.IsCMSScope &&
                                         this.AccountInfo.IsApproverDesignate.HasValue &&
                                         this.AccountInfo.IsApproverDesignate.Value;


            //General Rule: Admins of lower scope cannot approve Admins of higher scope.
            if (ApproverScope.IsLower(requestedScope))
            {
                return(false);
            }

            //Approve must always be Admin of some scope
            if (!ApproverRulesBLL.IsApprover(this.AccountInfo))
            {
                //if (!ApproverIsAdmin)
                return(false);
            }

            //CMS Admins can be approved by only approver designates.
            if (IsApproverCMSApprover)
            {
                return(true);
            }

            //CMS User/CMS Admin and CMS Regional requests can be approved only by a CMS Admin
            if (IsCMSRegionAccountRequested || IsCMSAccountRequested)
            {
                return(false);
            }


            //Move on to State Level Users Approval Request
            //For Non-CMS Users: States must match
            if (requestedState != ApproverState)
            {
                return(false);
            }
            else
            {
                //State Ship Directors can approve any one in the State.
                if (IsApproverShipDirector || IsApproverStateApprover)
                {
                    return(true);
                }

                if (requestedScope.IsEqual(Scope.State))
                {
                    //State Users can be approved by only State Directors or State Approvers.
                    //State Director and State approver rights were already checked, so need to reject all State requests.
                    return(false);
                }

                //For verifying Sub State access rights, lets get Sub State profiles of Approver
                IEnumerable <UserRegionalAccessProfile> approverSubStateAdminProfiles =
                    UserSubStateRegionBLL.GetUserSubStateRegionalProfiles(ApproverUserId, true);
                if (requestedScope.IsEqual(Scope.SubStateRegion))
                {
                    //Approvers of Sub State Users and Admins can be the following:
                    // CMS Approver - which we already checked
                    // Ship Director & State Approvers - which we already checked.
                    //Now check for Sub State Approver of the Sub State ID requested.

                    //Approve must be Sub State Admin to approve a Sub State User
                    if (approverSubStateAdminProfiles != null && approverSubStateAdminProfiles.Count() > 0)
                    {
                        //Sub State User can be approved by Sub State Admin of Same Sub State Region
                        int SubStateRegionIDOfRequestor = ViewData.RegionalProfiles[0].RegionId;
                        foreach (UserRegionalAccessProfile approverSubState in approverSubStateAdminProfiles)
                        {
                            if (approverSubState.RegionId == SubStateRegionIDOfRequestor)
                            {
                                return(approverSubState.IsApproverDesignate);
                            }
                        }
                    }
                    return(false);
                }

                //Logic below is for Agency Scope account approval requests.
                //Agency Scope requests can be approved by Sub State Approvers as well as Agency Approvers.
                if (ApproverScope.IsEqual(Scope.SubStateRegion))
                {
                    if (approverSubStateAdminProfiles != null && approverSubStateAdminProfiles.Count() > 0)
                    {
                        //The Agency of the account requested must be part of Approver's Sub State region.
                        int AgencyOfAccountRequested = ViewData.RegionalProfiles[0].RegionId;
                        foreach (UserRegionalAccessProfile subStateprofile in approverSubStateAdminProfiles)
                        {
                            //Get Agencies for substate
                            IEnumerable <ShiptalkLogic.BusinessObjects.Agency> agencyProfiles = LookupBLL.GetAgenciesForSubStateRegion(subStateprofile.RegionId);
                            foreach (ShiptalkLogic.BusinessObjects.Agency agency in agencyProfiles)
                            {
                                if (agency.Id == AgencyOfAccountRequested)
                                {
                                    return(subStateprofile.IsApproverDesignate);
                                }
                            }
                        }
                    }
                    return(false);
                }
                else
                {
                    //Here, it is evident that Approver is an Agency Level person and also account Request is for agency scope.
                    //All Agency requests could be approved by Agency Approvers, SubState approvers or Ship Director or CMS approvers
                    int AgencyOfAccountRequested = ViewData.RegionalProfiles[0].RegionId;
                    IEnumerable <UserRegionalAccessProfile> approverAgencyAdminProfiles =
                        UserAgencyBLL.GetUserAgencyProfiles(ApproverUserId, true);

                    foreach (UserRegionalAccessProfile approverAgencyprofile in approverAgencyAdminProfiles)
                    {
                        if (approverAgencyprofile.RegionId == AgencyOfAccountRequested)
                        {
                            return(approverAgencyprofile.IsApproverDesignate);
                        }
                    }
                    return(false);
                }
            }
        }
Ejemplo n.º 8
0
        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;
        }