Пример #1
0
        /// <summary>
        /// Gets the relevant Guid for the level of internal authorisation sent
        /// i.e. If this is a 'User' level of authorisation, then the current user AppUserId is returned.
        /// </summary>
        /// <param name="authorisationLevel"></param>
        /// <param name="user"></param>
        /// <returns></returns>
        public static Guid GetAuthorisationId(InternalSearchLevelEnum authorisationLevel, IPrincipal user)
        {
            Guid id = Guid.Empty;

            AppUser         appUser  = AppUserHelpers.GetAppUser(user);
            Branch          branch   = BranchHelpers.GetBranch(appUser.CurrentBranchId);
            AppUserSettings settings = AppUserSettingsHelpers.GetAppUserSettingsForUser(appUser.AppUserId);

            switch (settings.OrdersDespatchedAuthorisationManageViewLevel)
            {
            case InternalSearchLevelEnum.User:
                id = appUser.AppUserId;
                break;

            case InternalSearchLevelEnum.Branch:
                id = branch.BranchId;
                break;

            case InternalSearchLevelEnum.Company:
                id = branch.CompanyId;
                break;

            case InternalSearchLevelEnum.Group:     //TO BE DONE LSLSLS
                id = appUser.AppUserId;
                break;
            }

            return(id);
        }
Пример #2
0
        public static void SetOrderButtons(ApplicationDbContext db, IPrincipal user, Order order, bool orderOut, out bool?displayDespatchButton, out bool?displayDeliveredButton, out bool?displayReceivedButton, out bool?displayCollectedButton, out bool?displayClosedButton)
        {
            //Get settings for logged in user
            AppUserSettings settings = AppUserSettingsHelpers.GetAppUserSettingsForUser(db, user);

            //Set the authorisation levels and IDs for button activation on form
            InternalSearchLevelEnum despatchedAuthorisationLevel = settings.OrdersDespatchedAuthorisationManageViewLevel;
            Guid despatchedAuthorisationId = DataHelpers.GetAuthorisationId(settings.OrdersDespatchedAuthorisationManageViewLevel, user);
            InternalSearchLevelEnum deliveredAuthorisationLevel = settings.OrdersDeliveredAuthorisationManageViewLevel;
            Guid deliveredAuthorisationId = DataHelpers.GetAuthorisationId(settings.OrdersDeliveredAuthorisationManageViewLevel, user);
            InternalSearchLevelEnum receivedAuthorisationLevel = settings.OrdersReceivedAuthorisationManageViewLevel;
            Guid receivedAuthorisationId = DataHelpers.GetAuthorisationId(settings.OrdersReceivedAuthorisationManageViewLevel, user);
            InternalSearchLevelEnum collectedAuthorisationLevel = settings.OrdersCollectedAuthorisationManageViewLevel;
            Guid collectedAuthorisationId = DataHelpers.GetAuthorisationId(settings.OrdersCollectedAuthorisationManageViewLevel, user);
            InternalSearchLevelEnum closedAuthorisationLevel = settings.OrdersClosedAuthorisationManageViewLevel;
            Guid closedAuthorisationId = DataHelpers.GetAuthorisationId(settings.OrdersClosedAuthorisationManageViewLevel, user);

            //set buttons
            if (orderOut)
            {
                displayDespatchButton  = true;
                displayDeliveredButton = true;
                displayReceivedButton  = null;
                displayCollectedButton = null;
                displayClosedButton    = true;

                switch (despatchedAuthorisationLevel)
                {
                case InternalSearchLevelEnum.Company:
                    if (order.OrderOriginatorCompanyId != despatchedAuthorisationId && order.OfferOriginatorCompanyId != despatchedAuthorisationId)
                    {
                        displayDespatchButton = false;
                    }
                    break;

                case InternalSearchLevelEnum.Branch:
                    if (order.OrderOriginatorBranchId != despatchedAuthorisationId && order.OfferOriginatorBranchId != despatchedAuthorisationId)
                    {
                        displayDespatchButton = false;
                    }
                    break;

                case InternalSearchLevelEnum.User:
                    if (order.OrderOriginatorAppUserId != despatchedAuthorisationId && order.OfferOriginatorAppUserId != despatchedAuthorisationId)
                    {
                        displayDespatchButton = false;
                    }
                    break;

                case InternalSearchLevelEnum.Group:       //LSLSLS  TO BE DONE WHEN GROUPS ADDED
                    break;
                }

                switch (deliveredAuthorisationLevel)
                {
                case InternalSearchLevelEnum.Company:
                    if (order.OrderOriginatorCompanyId != deliveredAuthorisationId && order.OfferOriginatorCompanyId != deliveredAuthorisationId)
                    {
                        displayDeliveredButton = false;
                    }
                    break;

                case InternalSearchLevelEnum.Branch:
                    if (order.OrderOriginatorBranchId != deliveredAuthorisationId && order.OfferOriginatorBranchId != deliveredAuthorisationId)
                    {
                        displayDespatchButton = false;
                    }
                    break;

                case InternalSearchLevelEnum.User:
                    if (order.OrderOriginatorAppUserId != deliveredAuthorisationId && order.OfferOriginatorAppUserId != deliveredAuthorisationId)
                    {
                        displayDespatchButton = false;
                    }
                    break;

                case InternalSearchLevelEnum.Group:       //LSLSLS  TO BE DONE WHEN GROUPS ADDED
                    break;
                }

                switch (closedAuthorisationLevel)
                {
                case InternalSearchLevelEnum.Company:
                    if (order.OrderOriginatorCompanyId != closedAuthorisationId && order.OfferOriginatorCompanyId != closedAuthorisationId)
                    {
                        displayClosedButton = false;
                    }
                    break;

                case InternalSearchLevelEnum.Branch:
                    if (order.OrderOriginatorBranchId != closedAuthorisationId && order.OfferOriginatorBranchId != closedAuthorisationId)
                    {
                        displayClosedButton = false;
                    }
                    break;

                case InternalSearchLevelEnum.User:
                    if (order.OrderOriginatorAppUserId != closedAuthorisationId && order.OfferOriginatorAppUserId != closedAuthorisationId)
                    {
                        displayClosedButton = false;
                    }
                    break;

                case InternalSearchLevelEnum.Group:       //LSLSLS  TO BE DONE WHEN GROUPS ADDED
                    break;
                }
            }
            else
            {
                displayDespatchButton  = null;
                displayDeliveredButton = null;
                displayReceivedButton  = true;
                displayCollectedButton = true;
                displayClosedButton    = true;

                switch (collectedAuthorisationLevel)
                {
                case InternalSearchLevelEnum.Company:
                    if (order.OrderOriginatorCompanyId != collectedAuthorisationId && order.OfferOriginatorCompanyId != collectedAuthorisationId)
                    {
                        displayCollectedButton = false;
                    }
                    break;

                case InternalSearchLevelEnum.Branch:
                    if (order.OrderOriginatorBranchId != collectedAuthorisationId && order.OfferOriginatorBranchId != collectedAuthorisationId)
                    {
                        displayCollectedButton = false;
                    }
                    break;

                case InternalSearchLevelEnum.User:
                    if (order.OrderOriginatorAppUserId != collectedAuthorisationId && order.OfferOriginatorAppUserId != collectedAuthorisationId)
                    {
                        displayCollectedButton = false;
                    }
                    break;

                case InternalSearchLevelEnum.Group:       //LSLSLS  TO BE DONE WHEN GROUPS ADDED
                    break;
                }

                switch (receivedAuthorisationLevel)
                {
                case InternalSearchLevelEnum.Company:
                    if (order.OrderOriginatorCompanyId != receivedAuthorisationId && order.OfferOriginatorCompanyId != receivedAuthorisationId)
                    {
                        displayReceivedButton = false;
                    }
                    break;

                case InternalSearchLevelEnum.Branch:
                    if (order.OrderOriginatorBranchId != receivedAuthorisationId && order.OfferOriginatorBranchId != receivedAuthorisationId)
                    {
                        displayReceivedButton = false;
                    }
                    break;

                case InternalSearchLevelEnum.User:
                    if (order.OrderOriginatorAppUserId != receivedAuthorisationId && order.OfferOriginatorAppUserId != receivedAuthorisationId)
                    {
                        displayReceivedButton = false;
                    }
                    break;

                case InternalSearchLevelEnum.Group:       //LSLSLS  TO BE DONE WHEN GROUPS ADDED
                    break;
                }

                switch (closedAuthorisationLevel)
                {
                case InternalSearchLevelEnum.Company:
                    if (order.OrderOriginatorCompanyId != closedAuthorisationId && order.OfferOriginatorCompanyId != closedAuthorisationId)
                    {
                        displayClosedButton = false;
                    }
                    break;

                case InternalSearchLevelEnum.Branch:
                    if (order.OrderOriginatorBranchId != closedAuthorisationId && order.OfferOriginatorBranchId != closedAuthorisationId)
                    {
                        displayClosedButton = false;
                    }
                    break;

                case InternalSearchLevelEnum.User:
                    if (order.OrderOriginatorAppUserId != closedAuthorisationId && order.OfferOriginatorAppUserId != closedAuthorisationId)
                    {
                        displayClosedButton = false;
                    }
                    break;

                case InternalSearchLevelEnum.Group:       //LSLSLS  TO BE DONE WHEN GROUPS ADDED
                    break;
                }
            }
        }
Пример #3
0
        public static AppUserSettings CreateAppUserSettings(Guid appUserId,
                                                            int?campaignDashboardMaxDistance,
                                                            double?campaignDashboardMaxAge,
                                                            int?requiredListingDashboardMaxDistance,
                                                            double?requiredListingDashboardMaxAge,
                                                            int?availableListingDashboardMaxDistance,
                                                            double?availableListingDashboardMaxAge,
                                                            ExternalSearchLevelEnum campaignDashboardExternalSelectionLevel,
                                                            ExternalSearchLevelEnum requiredListingDashboardtExternalSelectionLevel,
                                                            ExternalSearchLevelEnum availableListingDashboardExternalSelectionLevel,
                                                            bool campaignGeneralInfoDisplayMyUserListings,
                                                            bool campaignGeneralInfoDisplayMyBranchListings,
                                                            bool campaignGeneralInfoDisplayMyCompanyListings,
                                                            bool campaignGeneralInfoDisplayBlockedListings,
                                                            int?campaignGeneralInfoMaxDistance,
                                                            bool requiredListingGeneralInfoDisplayMyUserListings,
                                                            bool requiredListingGeneralInfoDisplayMyBranchListings,
                                                            bool requiredListingGeneralInfoDisplayMyCompanyListings,
                                                            bool requiredListingGeneralInfoDisplayBlockedListings,
                                                            int?requiredListingGeneralInfoMaxDistance,
                                                            bool availableListingGeneralInfoDisplayMyUserListings,
                                                            bool availableListingGeneralInfoDisplayMyBranchListings,
                                                            bool availableListingGeneralInfoDisplayMyCompanyListings,
                                                            bool availableListingGeneralInfoDisplayBlockedListings,
                                                            int?availableListingGeneralInfoMaxDistance,
                                                            ExternalSearchLevelEnum campaignGeneralInfoExternalSelectionLevel,
                                                            ExternalSearchLevelEnum requiredListingGeneralInfoExternalSelectionLevel,
                                                            ExternalSearchLevelEnum availableListingGeneralInfoExternalSelectionLevel,
                                                            InternalSearchLevelEnum campaignManageViewInternalSelectionLevel,
                                                            InternalSearchLevelEnum requiredListingManageViewInternalSelectionLevel,
                                                            InternalSearchLevelEnum availableListingManageViewInternalSelectionLevel,
                                                            InternalSearchLevelEnum offersManageViewInternalSelectionLevel,
                                                            InternalSearchLevelEnum offersAcceptedAuthorisationManageViewLevel,
                                                            InternalSearchLevelEnum offersRejectedAuthorisationManageViewLevel,
                                                            InternalSearchLevelEnum offersReturnedAuthorisationManageViewLevel,
                                                            InternalSearchLevelEnum ordersManageViewInternalSelectionLevel,
                                                            InternalSearchLevelEnum ordersDespatchedAuthorisationManageViewLevel,
                                                            InternalSearchLevelEnum ordersDeliveredAuthorisationManageViewLevel,
                                                            InternalSearchLevelEnum ordersReceivedAuthorisationManageViewLevel,
                                                            InternalSearchLevelEnum ordersCollectedAuthorisationManageViewLevel,
                                                            InternalSearchLevelEnum ordersClosedAuthorisationManageViewLevel)
        {
            ApplicationDbContext db = new ApplicationDbContext();
            AppUserSettings      appUserSettings = CreateAppUserSettings(db,
                                                                         appUserId,
                                                                         campaignDashboardMaxDistance,
                                                                         campaignDashboardMaxAge,
                                                                         requiredListingDashboardMaxDistance,
                                                                         requiredListingDashboardMaxAge,
                                                                         availableListingDashboardMaxDistance,
                                                                         availableListingDashboardMaxAge,
                                                                         campaignDashboardExternalSelectionLevel,
                                                                         requiredListingDashboardtExternalSelectionLevel,
                                                                         availableListingDashboardExternalSelectionLevel,
                                                                         campaignGeneralInfoDisplayMyUserListings,
                                                                         campaignGeneralInfoDisplayMyBranchListings,
                                                                         campaignGeneralInfoDisplayMyCompanyListings,
                                                                         campaignGeneralInfoDisplayBlockedListings,
                                                                         campaignGeneralInfoMaxDistance,
                                                                         requiredListingGeneralInfoDisplayMyUserListings,
                                                                         requiredListingGeneralInfoDisplayMyBranchListings,
                                                                         requiredListingGeneralInfoDisplayMyCompanyListings,
                                                                         requiredListingGeneralInfoDisplayBlockedListings,
                                                                         requiredListingGeneralInfoMaxDistance,
                                                                         availableListingGeneralInfoDisplayMyUserListings,
                                                                         availableListingGeneralInfoDisplayMyBranchListings,
                                                                         availableListingGeneralInfoDisplayMyCompanyListings,
                                                                         availableListingGeneralInfoDisplayBlockedListings,
                                                                         availableListingGeneralInfoMaxDistance,
                                                                         campaignGeneralInfoExternalSelectionLevel,
                                                                         requiredListingGeneralInfoExternalSelectionLevel,
                                                                         availableListingGeneralInfoExternalSelectionLevel,
                                                                         campaignManageViewInternalSelectionLevel,
                                                                         requiredListingManageViewInternalSelectionLevel,
                                                                         availableListingManageViewInternalSelectionLevel,
                                                                         offersManageViewInternalSelectionLevel,
                                                                         offersAcceptedAuthorisationManageViewLevel,
                                                                         offersRejectedAuthorisationManageViewLevel,
                                                                         offersReturnedAuthorisationManageViewLevel,
                                                                         ordersManageViewInternalSelectionLevel,
                                                                         ordersDespatchedAuthorisationManageViewLevel,
                                                                         ordersDeliveredAuthorisationManageViewLevel,
                                                                         ordersReceivedAuthorisationManageViewLevel,
                                                                         ordersCollectedAuthorisationManageViewLevel,
                                                                         ordersClosedAuthorisationManageViewLevel);

            db.Dispose();
            return(appUserSettings);
        }
Пример #4
0
        public static AppUserSettings CreateAppUserSettings(ApplicationDbContext db, Guid appUserId,
                                                            int?campaignDashboardMaxDistance,
                                                            double?campaignDashboardMaxAge,
                                                            int?requiredListingDashboardMaxDistance,
                                                            double?requiredListingDashboardMaxAge,
                                                            int?availableListingDashboardMaxDistance,
                                                            double?availableListingDashboardMaxAge,
                                                            ExternalSearchLevelEnum campaignDashboardExternalSelectionLevel,
                                                            ExternalSearchLevelEnum requiredListingDashboardExternalSelectionLevel,
                                                            ExternalSearchLevelEnum availableListingDashboardExternalSelectionLevel,
                                                            bool campaignGeneralInfoDisplayMyUserListings,
                                                            bool campaignGeneralInfoDisplayMyBranchListings,
                                                            bool campaignGeneralInfoDisplayMyCompanyListings,
                                                            bool campaignGeneralInfoDisplayBlockedListings,
                                                            int?campaignGeneralInfoMaxDistance,
                                                            bool requiredListingGeneralInfoDisplayMyUserListings,
                                                            bool requiredListingGeneralInfoDisplayMyBranchListings,
                                                            bool requiredListingGeneralInfoDisplayMyCompanyListings,
                                                            bool requiredListingGeneralInfoDisplayBlockedListings,
                                                            int?requiredListingGeneralInfoMaxDistance,
                                                            bool availableListingGeneralInfoDisplayMyUserListings,
                                                            bool availableListingGeneralInfoDisplayMyBranchListings,
                                                            bool availableListingGeneralInfoDisplayMyCompanyListings,
                                                            bool availableListingGeneralInfoDisplayBlockedListings,
                                                            int?availableListingGeneralInfoMaxDistance,
                                                            ExternalSearchLevelEnum campaignGeneralInfoExternalSelectionLevel,
                                                            ExternalSearchLevelEnum requiredListingGeneralInfoExternalSelectionLevel,
                                                            ExternalSearchLevelEnum availableListingGeneralInfoExternalSelectionLevel,
                                                            InternalSearchLevelEnum campaignManageViewInternalSelectionLevel,
                                                            InternalSearchLevelEnum requiredListingManageViewInternalSelectionLevel,
                                                            InternalSearchLevelEnum availableListingManageViewInternalSelectionLevel,
                                                            InternalSearchLevelEnum offersManageViewInternalSelectionLevel,
                                                            InternalSearchLevelEnum offersAcceptedAuthorisationManageViewLevel,
                                                            InternalSearchLevelEnum offersRejectedAuthorisationManageViewLevel,
                                                            InternalSearchLevelEnum offersReturnedAuthorisationManageViewLevel,
                                                            InternalSearchLevelEnum ordersManageViewInternalSelectionLevel,
                                                            InternalSearchLevelEnum ordersDespatchedAuthorisationManageViewLevel,
                                                            InternalSearchLevelEnum ordersDeliveredAuthorisationManageViewLevel,
                                                            InternalSearchLevelEnum ordersReceivedAuthorisationManageViewLevel,
                                                            InternalSearchLevelEnum ordersCollectedAuthorisationManageViewLevel,
                                                            InternalSearchLevelEnum ordersClosedAuthorisationManageViewLevel)
        {
            AppUserSettings appUserSettings = new AppUserSettings()
            {
                AppUserSettingsId                                   = Guid.NewGuid(),
                AppUserId                                           = appUserId,
                CampaignDashboardMaxDistance                        = campaignDashboardMaxDistance,
                CampaignDashboardMaxAge                             = campaignDashboardMaxAge,
                RequiredListingDashboardMaxDistance                 = requiredListingDashboardMaxDistance,
                RequiredListingDashboardMaxAge                      = requiredListingDashboardMaxAge,
                AvailableListingDashboardMaxDistance                = availableListingDashboardMaxDistance,
                AvailableListingDashboardMaxAge                     = availableListingDashboardMaxAge,
                CampaignDashboardExternalSelectionLevel             = campaignDashboardExternalSelectionLevel,
                RequiredListingDashboardExternalSelectionLevel      = requiredListingDashboardExternalSelectionLevel,
                AvailableListingDashboardExternalSelectionLevel     = availableListingDashboardExternalSelectionLevel,
                CampaignGeneralInfoDisplayMyUserListings            = campaignGeneralInfoDisplayMyUserListings,
                CampaignGeneralInfoDisplayMyBranchListings          = campaignGeneralInfoDisplayMyBranchListings,
                CampaignGeneralInfoDisplayMyCompanyListings         = campaignGeneralInfoDisplayMyCompanyListings,
                CampaignGeneralInfoDisplayBlockedListings           = campaignGeneralInfoDisplayBlockedListings,
                CampaignGeneralInfoMaxDistance                      = campaignGeneralInfoMaxDistance,
                RequiredListingGeneralInfoDisplayMyUserListings     = requiredListingGeneralInfoDisplayMyUserListings,
                RequiredListingGeneralInfoDisplayMyBranchListings   = requiredListingGeneralInfoDisplayMyBranchListings,
                RequiredListingGeneralInfoDisplayMyCompanyListings  = requiredListingGeneralInfoDisplayMyCompanyListings,
                RequiredListingGeneralInfoDisplayBlockedListings    = requiredListingGeneralInfoDisplayBlockedListings,
                RequiredListingGeneralInfoMaxDistance               = requiredListingGeneralInfoMaxDistance,
                AvailableListingGeneralInfoDisplayMyUserListings    = availableListingGeneralInfoDisplayMyUserListings,
                AvailableListingGeneralInfoDisplayMyBranchListings  = availableListingGeneralInfoDisplayMyBranchListings,
                AvailableListingGeneralInfoDisplayMyCompanyListings = availableListingGeneralInfoDisplayMyCompanyListings,
                AvailableListingGeneralInfoDisplayBlockedListings   = availableListingGeneralInfoDisplayBlockedListings,
                AvailableListingGeneralInfoMaxDistance              = availableListingGeneralInfoMaxDistance,
                CampaignGeneralInfoExternalSelectionLevel           = campaignGeneralInfoExternalSelectionLevel,
                RequiredListingGeneralInfoExternalSelectionLevel    = requiredListingGeneralInfoExternalSelectionLevel,
                AvailableListingGeneralInfoExternalSelectionLevel   = availableListingGeneralInfoExternalSelectionLevel,
                CampaignManageViewInternalSelectionLevel            = campaignManageViewInternalSelectionLevel,
                RequiredListingManageViewInternalSelectionLevel     = requiredListingManageViewInternalSelectionLevel,
                AvailableListingManageViewInternalSelectionLevel    = availableListingManageViewInternalSelectionLevel,
                OffersManageViewInternalSelectionLevel              = offersManageViewInternalSelectionLevel,
                OffersAcceptedAuthorisationManageViewLevel          = offersAcceptedAuthorisationManageViewLevel,
                OffersRejectedAuthorisationManageViewLevel          = offersRejectedAuthorisationManageViewLevel,
                OffersReturnedAuthorisationManageViewLevel          = offersReturnedAuthorisationManageViewLevel,
                OrdersManageViewInternalSelectionLevel              = ordersManageViewInternalSelectionLevel,
                OrdersDespatchedAuthorisationManageViewLevel        = ordersDespatchedAuthorisationManageViewLevel,
                OrdersDeliveredAuthorisationManageViewLevel         = ordersDeliveredAuthorisationManageViewLevel,
                OrdersReceivedAuthorisationManageViewLevel          = ordersReceivedAuthorisationManageViewLevel,
                OrdersCollectedAuthorisationManageViewLevel         = ordersCollectedAuthorisationManageViewLevel,
                OrdersClosedAuthorisationManageViewLevel            = ordersClosedAuthorisationManageViewLevel
            };

            db.AppUserSettings.Add(appUserSettings);
            db.SaveChanges();

            return(appUserSettings);
        }