Exemple #1
0
        public static void DeleteAppUserSettingsForUser(ApplicationDbContext db, Guid appUserId)
        {
            AppUserSettings appUserSettings = AppUserSettingsHelpers.GetAppUserSettingsForUser(db, appUserId);

            db.AppUserSettings.Remove(appUserSettings);
            db.SaveChanges();
        }
Exemple #2
0
        public static List <Offer> GetAllManageListingFilteredOffers(ApplicationDbContext db, Guid appUserId, bool getHistory)
        {
            AppUser         appUser  = AppUserHelpers.GetAppUser(db, appUserId);
            Branch          branch   = BranchHelpers.GetBranch(db, appUser.CurrentBranchId);
            AppUserSettings settings = AppUserSettingsHelpers.GetAppUserSettingsForUser(db, appUserId);

            //Create list
            List <Offer> list = new List <Offer>();

            //Now bring in the Selection Level sort
            switch (settings.OffersManageViewInternalSelectionLevel)
            {
            case InternalSearchLevelEnum.User:
                list = GetAllOffersForUser(db, appUserId, getHistory);
                break;

            case InternalSearchLevelEnum.Branch:     //user's current branch to filter
                list = GetAllOffersForBranch(db, branch.BranchId, getHistory);
                break;

            case InternalSearchLevelEnum.Company:     //user's current company to filter
                list = GetAllOffersForCompany(db, branch.CompanyId, getHistory);
                break;

            case InternalSearchLevelEnum.Group:     //user's built group sets to filter ***TO BE DONE***
                break;
            }

            return(list);
        }
Exemple #3
0
        public static List <AvailableListing> GetAllManageListingFilteredAvailableListings(ApplicationDbContext db, Guid appUserId, bool getHistory)
        {
            AppUser         appUser  = AppUserHelpers.GetAppUser(db, appUserId);
            Branch          branch   = BranchHelpers.GetBranch(db, appUser.CurrentBranchId);
            AppUserSettings settings = AppUserSettingsHelpers.GetAppUserSettingsForUser(db, appUserId);

            var dateCheck = DateTime.MinValue;

            //Create list within the time frame if setting set
            List <AvailableListing> list = new List <AvailableListing>();

            //Now bring in the Selection Level sort
            switch (settings.AvailableListingManageViewInternalSelectionLevel)
            {
            case InternalSearchLevelEnum.User:
                list = GetAllAvailableListingsForUser(db, appUserId, getHistory);
                break;

            case InternalSearchLevelEnum.Branch:     //user's current branch to filter
                list = GetAllAvailableListingsForBranch(db, branch.BranchId, getHistory);
                break;

            case InternalSearchLevelEnum.Company:     //user's current company to filter
                list = GetAllAvailableListingsForCompany(db, branch.CompanyId, getHistory);
                break;

            case InternalSearchLevelEnum.Group:     //user's built group sets to filter ***TO BE DONE***
                break;
            }

            return(list);
        }
Exemple #4
0
        public static AppUser UpdateAppUserFromAppUserEditView(ApplicationDbContext db, AppUserEditView view)
        {
            //Update AppUser
            AppUser appUser = GetAppUser(db, view.AppUserId);

            appUser.FirstName    = view.FirstName;
            appUser.LastName     = view.LastName;
            appUser.EntityStatus = view.EntityStatus;
            appUser.PrivacyLevel = view.PrivacyLevel;

            if (view.SelectedBranchId != null)
            {
                appUser.CurrentBranchId = view.SelectedBranchId.Value;
            }
            db.Entry(appUser).State = EntityState.Modified;
            db.SaveChanges();

            //Update BranchUser (Role)
            BranchUser branchUser = BranchUserHelpers.GetBranchUser(db, appUser.AppUserId, appUser.CurrentBranchId);

            BranchUserHelpers.UpdateBranchUserRole(db, branchUser.BranchUserId, view.UserRole);

            //Update UserSettings
            AppUserSettingsHelpers.UpdateUserSettingsFromAppUserEditView(db, view);

            return(appUser);
        }
Exemple #5
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);
        }
Exemple #6
0
        public static List <AvailableListing> GetAllGeneralInfoFilteredAvailableListings(ApplicationDbContext db, Guid appUserId)
        {
            AppUser         appUser  = AppUserHelpers.GetAppUser(db, appUserId);
            Branch          branch   = BranchHelpers.GetBranch(db, appUser.CurrentBranchId);
            AppUserSettings settings = AppUserSettingsHelpers.GetAppUserSettingsForUser(db, appUserId);

            var dateCheck           = DateTime.MinValue;
            int settingsMaxDistance = settings.AvailableListingGeneralInfoMaxDistance ?? 0;

            //Create list within the time frame if setting set
            List <AvailableListing> list = (from rl in db.AvailableListings
                                            where ((rl.ListingStatus == ItemRequiredListingStatusEnum.Open || rl.ListingStatus == ItemRequiredListingStatusEnum.Partial) &&
                                                   rl.ListingOriginatorDateTime >= dateCheck)
                                            orderby rl.AvailableTo ?? DateTime.MaxValue
                                            select rl).ToList();

            //Now bring in the Selection Level sort
            switch (settings.AvailableListingGeneralInfoExternalSelectionLevel)
            {
            case ExternalSearchLevelEnum.All:     //do nothing
                break;

            case ExternalSearchLevelEnum.Branch:     //user's current branch to filter
                list = list.Where(l => l.ListingOriginatorBranchId == branch.BranchId).ToList();
                break;

            case ExternalSearchLevelEnum.Company:     //user's current company to filter
                list = list.Where(l => l.ListingOriginatorCompanyId == branch.CompanyId).ToList();
                break;

            case ExternalSearchLevelEnum.Group:     //LSLSLS user's built group sets to filter ***TO BE DONE***
                break;
            }

            //Now sort by distance
            if (settingsMaxDistance > 0)
            {
                List <AvailableListing> removeList = new List <AvailableListing>();

                foreach (AvailableListing listing in list)
                {
                    DistanceHelpers distance      = new DistanceHelpers();
                    int             distanceValue = distance.GetDistance(branch.AddressPostcode, listing.ListingBranchPostcode);

                    if (distanceValue > settingsMaxDistance)
                    {
                        removeList.Add(listing);
                    }
                }

                if (removeList.Count > 0)
                {
                    list.RemoveAll(l => removeList.Contains(l));
                }
            }

            return(list);
        }
        public static List <Campaign> GetAllGeneralInfoFilteredCampaigns(ApplicationDbContext db, Guid appUserId)
        {
            AppUser         appUser  = AppUserHelpers.GetAppUser(db, appUserId);
            Branch          branch   = BranchHelpers.GetBranch(db, appUser.CurrentBranchId);
            AppUserSettings settings = AppUserSettingsHelpers.GetAppUserSettingsForUser(db, appUserId);

            var dateCheck           = DateTime.MinValue;
            int settingsMaxDistance = settings.CampaignGeneralInfoMaxDistance ?? 0;

            //Create list within the time frame if setting set
            List <Campaign> list = (from c in db.Campaigns
                                    where (c.EntityStatus == EntityStatusEnum.Active && c.CampaignOriginatorDateTime >= dateCheck)
                                    orderby c.CampaignEndDateTime ?? DateTime.MaxValue
                                    select c).ToList();

            //Now bring in the Selection Level sort
            switch (settings.CampaignGeneralInfoExternalSelectionLevel)
            {
            case ExternalSearchLevelEnum.All:     //do nothing
                break;

            case ExternalSearchLevelEnum.Branch:     //user's current branch to filter
                list = list.Where(l => l.CampaignOriginatorBranchId == branch.BranchId).ToList();
                break;

            case ExternalSearchLevelEnum.Company:     //user's current company to filter
                list = list.Where(l => l.CampaignOriginatorCompanyId == branch.CompanyId).ToList();
                break;

            case ExternalSearchLevelEnum.Group:     //user's built group sets to filter ***TO BE DONE***
                break;
            }

            //Now sort by distance
            if (settingsMaxDistance > 0)
            {
                List <Campaign> removeList = new List <Campaign>();

                foreach (Campaign campaign in list)
                {
                    DistanceHelpers distance      = new DistanceHelpers();
                    int             distanceValue = distance.GetDistance(branch.AddressPostcode, campaign.LocationAddressPostcode);

                    if (distanceValue > settingsMaxDistance)
                    {
                        removeList.Add(campaign);
                    }
                }

                if (removeList.Count > 0)
                {
                    list.RemoveAll(l => removeList.Contains(l));
                }
            }

            return(list);
        }
Exemple #8
0
        public static OfferManageView GetOfferManageViewForOffer(ApplicationDbContext db, Offer offer, IPrincipal user)
        {
            AppUser offerAppUser = AppUserHelpers.GetAppUser(db, offer.OfferOriginatorAppUserId);

            AvailableListing   availableListing   = null;
            RequirementListing requirementListing = null;
            AppUser            listingAppUser     = null;

            switch (offer.ListingType)
            {
            case ListingTypeEnum.Available:
                availableListing = AvailableListingHelpers.GetAvailableListing(db, offer.ListingId);
                listingAppUser   = AppUserHelpers.GetAppUser(db, availableListing.ListingOriginatorAppUserId);
                break;

            case ListingTypeEnum.Requirement:
                requirementListing = RequirementListingHelpers.GetRequirementListing(db, offer.ListingId);
                listingAppUser     = AppUserHelpers.GetAppUser(db, requirementListing.ListingOriginatorAppUserId);
                break;
            }

            OfferManageView offerManageView = new OfferManageView()
            {
                OfferDetails              = offer,
                AvailableListingDetails   = availableListing,
                RequirementListingDetails = requirementListing,
                OfferAppUserDetails       = offerAppUser,
                ListingAppUserDetails     = listingAppUser,
                OfferBranchDetails        = BranchHelpers.GetBranch(db, offerAppUser.CurrentBranchId),
                ListingBranchDetails      = BranchHelpers.GetBranch(db, listingAppUser.CurrentBranchId),
                OfferAppUserSettings      = AppUserSettingsHelpers.GetAppUserSettingsForUser(db, offerAppUser.AppUserId),
                ListingAppUserSettings    = AppUserSettingsHelpers.GetAppUserSettingsForUser(db, listingAppUser.AppUserId)
            };

            AppUser thisAppUser = AppUserHelpers.GetAppUser(db, user);
            //If we allow branch trading then differentiate between branches for in/out trading, otherwise it is at company level
            Company thisCompany = CompanyHelpers.GetCompanyForUser(db, user);

            //set Inhouse flag
            offerManageView.InhouseOffer = OfferProcessHelpers.SetInhouseFlag(offer, thisAppUser, thisCompany);

            //set buttons
            bool?displayAcceptButton  = null;
            bool?displayRejectButton  = null;
            bool?displayCounterButton = null;
            bool?displayOfferButton   = null;

            OfferProcessHelpers.SetOrderButtons(db, user, offerManageView, out displayAcceptButton, out displayRejectButton, out displayCounterButton, out displayOfferButton);

            offerManageView.DisplayAcceptButton  = displayAcceptButton;
            offerManageView.DisplayRejectButton  = displayRejectButton;
            offerManageView.DisplayCounterButton = displayCounterButton;
            offerManageView.DisplayOfferButton   = displayOfferButton;

            return(offerManageView);
        }
        public static List <CampaignGeneralInfoView> GetAllCampaignsGeneralInfoView(ApplicationDbContext db, IPrincipal user)
        {
            List <CampaignGeneralInfoView> allCampaignsGeneralInfoView = new List <CampaignGeneralInfoView>();

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

            List <Campaign> allCampaigns = CampaignHelpers.GetAllGeneralInfoFilteredCampaigns(db, appUser.AppUserId);

            foreach (Campaign campaign in allCampaigns)
            {
                bool userBlocked    = false;
                bool branchBlocked  = false;
                bool companyBlocked = false;

                BlockHelpers.GetBlocksForAllTypesForSpecificOfBy(db, campaign.CampaignOriginatorAppUserId, appUser.AppUserId, campaign.CampaignOriginatorBranchId, currentBranch.BranchId, campaign.CampaignOriginatorCompanyId, currentBranch.CompanyId, out userBlocked, out branchBlocked, out companyBlocked);

                bool userMatchedOwner    = false;
                bool branchMatchedOwner  = false;
                bool companyMatchedOwner = false;

                if (currentBranch.CompanyId == campaign.CampaignOriginatorCompanyId)
                {
                    companyMatchedOwner = true;
                }
                if (currentBranch.BranchId == campaign.CampaignOriginatorBranchId)
                {
                    branchMatchedOwner = true;
                }
                if (appUser.AppUserId == campaign.CampaignOriginatorAppUserId)
                {
                    userMatchedOwner = true;
                }

                CampaignGeneralInfoView campaignGeneralInfoView = new CampaignGeneralInfoView()
                {
                    Campaign                = campaign,
                    UserLevelBlock          = userBlocked,
                    BranchLevelBlock        = branchBlocked,
                    CompanyLevelBlock       = companyBlocked,
                    DisplayBlocks           = settings.CampaignGeneralInfoDisplayBlockedListings,
                    CompanyLevelOwner       = companyMatchedOwner,
                    DisplayMyCompanyRecords = settings.CampaignGeneralInfoDisplayMyUserListings,
                    BranchLevelOwner        = branchMatchedOwner,
                    DisplayMyBranchRecords  = settings.CampaignGeneralInfoDisplayMyBranchListings,
                    UserLevelOwner          = userMatchedOwner,
                    DisplayMyRecords        = settings.CampaignGeneralInfoDisplayMyUserListings
                };

                allCampaignsGeneralInfoView.Add(campaignGeneralInfoView);
            }

            return(allCampaignsGeneralInfoView);
        }
Exemple #10
0
        public static AppUserSettings UpdateUserSettingsFromAppUserEditView(ApplicationDbContext db, AppUserEditView view)
        {
            AppUserSettings settings = AppUserSettingsHelpers.GetAppUserSettings(db, view.AppUserSettingsId);

            settings.CampaignDashboardMaxDistance                        = view.CampaignDashboardMaxDistance;
            settings.CampaignDashboardMaxAge                             = view.CampaignDashboardMaxAge;
            settings.RequiredListingDashboardMaxDistance                 = view.RequiredListingDashboardMaxDistance;
            settings.RequiredListingDashboardMaxAge                      = view.RequiredListingDashboardMaxAge;
            settings.AvailableListingDashboardMaxDistance                = view.AvailableListingDashboardMaxDistance;
            settings.AvailableListingDashboardMaxAge                     = view.AvailableListingDashboardMaxAge;
            settings.CampaignDashboardExternalSelectionLevel             = view.CampaignDashboardExternalSelectionLevel;
            settings.RequiredListingDashboardExternalSelectionLevel      = view.RequiredListingDashboardExternalSelectionLevel;
            settings.AvailableListingDashboardExternalSelectionLevel     = view.AvailableListingDashboardExternalSelectionLevel;
            settings.CampaignGeneralInfoDisplayMyUserListings            = view.CampaignGeneralInfoDisplayMyUserListings;
            settings.CampaignGeneralInfoDisplayMyBranchListings          = view.CampaignGeneralInfoDisplayMyBranchListings;
            settings.CampaignGeneralInfoDisplayMyCompanyListings         = view.CampaignGeneralInfoDisplayMyCompanyListings;
            settings.CampaignGeneralInfoDisplayBlockedListings           = view.CampaignGeneralInfoDisplayBlockedListings;
            settings.CampaignGeneralInfoMaxDistance                      = view.CampaignGeneralInfoMaxDistance;
            settings.RequiredListingGeneralInfoDisplayMyUserListings     = view.RequiredListingGeneralInfoDisplayMyUserListings;
            settings.RequiredListingGeneralInfoDisplayMyBranchListings   = view.RequiredListingGeneralInfoDisplayMyBranchListings;
            settings.RequiredListingGeneralInfoDisplayMyCompanyListings  = view.RequiredListingGeneralInfoDisplayMyCompanyListings;
            settings.RequiredListingGeneralInfoDisplayBlockedListings    = view.RequiredListingGeneralInfoDisplayBlockedListings;
            settings.RequiredListingGeneralInfoMaxDistance               = view.RequiredListingGeneralInfoMaxDistance;
            settings.AvailableListingGeneralInfoDisplayMyUserListings    = view.AvailableListingGeneralInfoDisplayMyUserListings;
            settings.AvailableListingGeneralInfoDisplayMyBranchListings  = view.AvailableListingGeneralInfoDisplayMyBranchListings;
            settings.AvailableListingGeneralInfoDisplayMyCompanyListings = view.AvailableListingGeneralInfoDisplayMyCompanyListings;
            settings.AvailableListingGeneralInfoDisplayBlockedListings   = view.AvailableListingGeneralInfoDisplayBlockedListings;
            settings.AvailableListingGeneralInfoMaxDistance              = view.AvailableListingGeneralInfoMaxDistance;
            settings.CampaignManageViewInternalSelectionLevel            = view.CampaignManageViewInternalSelectionLevel;
            settings.RequiredListingManageViewInternalSelectionLevel     = view.RequiredListingManageViewInternalSelectionLevel;
            settings.AvailableListingManageViewInternalSelectionLevel    = view.AvailableListingManageViewInternalSelectionLevel;
            settings.OffersManageViewInternalSelectionLevel              = view.OffersManageViewInternalSelectionLevel;
            settings.OffersAcceptedAuthorisationManageViewLevel          = view.OffersAcceptedAuthorisationManageViewLevel;
            settings.OffersRejectedAuthorisationManageViewLevel          = view.OffersRejectedAuthorisationManageViewLevel;
            settings.OffersReturnedAuthorisationManageViewLevel          = view.OffersReturnedAuthorisationManageViewLevel;
            settings.OrdersManageViewInternalSelectionLevel              = view.OrdersManageViewInternalSelectionLevel;
            settings.OrdersDespatchedAuthorisationManageViewLevel        = view.OrdersDespatchedAuthorisationManageViewLevel;
            settings.OrdersDeliveredAuthorisationManageViewLevel         = view.OrdersDeliveredAuthorisationManageViewLevel;
            settings.OrdersReceivedAuthorisationManageViewLevel          = view.OrdersReceivedAuthorisationManageViewLevel;
            settings.OrdersCollectedAuthorisationManageViewLevel         = view.OrdersCollectedAuthorisationManageViewLevel;
            settings.OrdersClosedAuthorisationManageViewLevel            = view.OrdersClosedAuthorisationManageViewLevel;
            settings.CampaignGeneralInfoExternalSelectionLevel           = view.CampaignGeneralInfoExternalSelectionLevel;
            settings.RequiredListingGeneralInfoExternalSelectionLevel    = view.RequiredListingGeneralInfoExternalSelectionLevel;
            settings.AvailableListingGeneralInfoExternalSelectionLevel   = view.AvailableListingGeneralInfoExternalSelectionLevel;

            db.Entry(settings).State = EntityState.Modified;
            db.SaveChanges();

            return(settings);
        }
Exemple #11
0
        public static AppUser CreateAppUser(ApplicationDbContext db, string firstName, string lastName, Guid currentBranchId, EntityStatusEnum entityStatus, string loginEmail, PrivacyLevelEnum privacyLevel, UserRoleEnum userRole)
        {
            bool superUser = false;
            bool adminUser = false;

            if (userRole == UserRoleEnum.SuperUser)
            {
                superUser = true;
            }
            if (userRole == UserRoleEnum.Admin)
            {
                adminUser = true;
            }

            AppUser appUser = new AppUser()
            {
                AppUserId       = Guid.NewGuid(),
                FirstName       = firstName,
                LastName        = lastName,
                CurrentBranchId = currentBranchId,
                EntityStatus    = entityStatus,
                PrivacyLevel    = privacyLevel,
                LoginEmail      = loginEmail,
                SuperUser       = superUser,
                AdminUser       = adminUser
            };

            db.AppUsers.Add(appUser);

            //Create initial settings values from the settings template
            AppUserSettingsHelpers.CreateAppUserSettingsForNewUser(db, appUser.AppUserId, userRole);

            db.SaveChanges();

            return(appUser);
        }
Exemple #12
0
        public static void SetOrderButtons(ApplicationDbContext db, IPrincipal user, OfferManageView view, out bool?displayAcceptButton, out bool?displayRejectButton, out bool?displayCounterButton, out bool?displayOfferButton)
        {
            //Get settings for logged in user
            AppUserSettings settings = AppUserSettingsHelpers.GetAppUserSettingsForUser(db, user);

            Guid acceptedAuthorisationId = DataHelpers.GetAuthorisationId(settings.OffersAcceptedAuthorisationManageViewLevel, user);
            Guid rejectedAuthorisationId = DataHelpers.GetAuthorisationId(settings.OffersRejectedAuthorisationManageViewLevel, user);
            Guid returnedAuthorisationId = DataHelpers.GetAuthorisationId(settings.OffersReturnedAuthorisationManageViewLevel, user);

            //Set buttons
            displayAcceptButton  = true;
            displayRejectButton  = true;
            displayCounterButton = true;
            displayOfferButton   = true;

            if (view.InhouseOffer)
            {
                switch (view.OfferAppUserSettings.OffersAcceptedAuthorisationManageViewLevel)
                {
                case GeneralEnums.InternalSearchLevelEnum.Company:
                    if (view.OfferDetails.OfferOriginatorCompanyId != acceptedAuthorisationId)
                    {
                        displayAcceptButton = false;
                    }
                    break;

                case GeneralEnums.InternalSearchLevelEnum.Branch:
                    if (view.OfferDetails.OfferOriginatorBranchId != acceptedAuthorisationId)
                    {
                        displayAcceptButton = false;
                    }
                    break;

                case GeneralEnums.InternalSearchLevelEnum.User:
                    if (view.OfferDetails.OfferOriginatorAppUserId != acceptedAuthorisationId)
                    {
                        displayAcceptButton = false;
                    }
                    break;

                case GeneralEnums.InternalSearchLevelEnum.Group:      //LSLSLS  TO BE DONE WHEN GROUPS ADDED
                    break;
                }
                switch (view.OfferAppUserSettings.OffersRejectedAuthorisationManageViewLevel)
                {
                case GeneralEnums.InternalSearchLevelEnum.Company:
                    if (view.OfferDetails.OfferOriginatorCompanyId != rejectedAuthorisationId)
                    {
                        displayRejectButton = false;
                    }
                    break;

                case GeneralEnums.InternalSearchLevelEnum.Branch:
                    if (view.OfferDetails.OfferOriginatorBranchId != rejectedAuthorisationId)
                    {
                        displayRejectButton = false;
                    }
                    break;

                case GeneralEnums.InternalSearchLevelEnum.User:
                    if (view.OfferDetails.OfferOriginatorAppUserId != rejectedAuthorisationId)
                    {
                        displayRejectButton = false;
                    }
                    break;

                case GeneralEnums.InternalSearchLevelEnum.Group:      //LSLSLS  TO BE DONE WHEN GROUPS ADDED
                    break;
                }
                switch (view.OfferAppUserSettings.OffersReturnedAuthorisationManageViewLevel)
                {
                case GeneralEnums.InternalSearchLevelEnum.Company:
                    if (view.OfferDetails.OfferOriginatorCompanyId != returnedAuthorisationId)
                    {
                        displayOfferButton = false;
                    }
                    break;

                case GeneralEnums.InternalSearchLevelEnum.Branch:
                    if (view.OfferDetails.OfferOriginatorBranchId != returnedAuthorisationId)
                    {
                        displayOfferButton = false;
                    }
                    break;

                case GeneralEnums.InternalSearchLevelEnum.User:
                    if (view.OfferDetails.OfferOriginatorAppUserId != returnedAuthorisationId)
                    {
                        displayOfferButton = false;
                    }
                    break;

                case GeneralEnums.InternalSearchLevelEnum.Group:      //LSLSLS  TO BE DONE WHEN GROUPS ADDED
                    break;
                }
            }
            else
            {
                switch (view.ListingAppUserSettings.OffersAcceptedAuthorisationManageViewLevel)
                {
                case GeneralEnums.InternalSearchLevelEnum.Company:
                    if (view.OfferDetails.ListingOriginatorCompanyId != acceptedAuthorisationId)
                    {
                        displayAcceptButton = false;
                    }
                    break;

                case GeneralEnums.InternalSearchLevelEnum.Branch:
                    if (view.OfferDetails.ListingOriginatorBranchId != acceptedAuthorisationId)
                    {
                        displayAcceptButton = false;
                    }
                    break;

                case GeneralEnums.InternalSearchLevelEnum.User:
                    if (view.OfferDetails.ListingOriginatorAppUserId != acceptedAuthorisationId)
                    {
                        displayAcceptButton = false;
                    }
                    break;

                case GeneralEnums.InternalSearchLevelEnum.Group:      //LSLSLS  TO BE DONE WHEN GROUPS ADDED
                    break;
                }
                switch (view.ListingAppUserSettings.OffersRejectedAuthorisationManageViewLevel)
                {
                case GeneralEnums.InternalSearchLevelEnum.Company:
                    if (view.OfferDetails.ListingOriginatorCompanyId != rejectedAuthorisationId)
                    {
                        displayRejectButton = false;
                    }
                    break;

                case GeneralEnums.InternalSearchLevelEnum.Branch:
                    if (view.OfferDetails.ListingOriginatorBranchId != rejectedAuthorisationId)
                    {
                        displayRejectButton = false;
                    }
                    break;

                case GeneralEnums.InternalSearchLevelEnum.User:
                    if (view.OfferDetails.ListingOriginatorAppUserId != rejectedAuthorisationId)
                    {
                        displayRejectButton = false;
                    }
                    break;

                case GeneralEnums.InternalSearchLevelEnum.Group:      //LSLSLS  TO BE DONE WHEN GROUPS ADDED
                    break;
                }
                switch (view.ListingAppUserSettings.OffersReturnedAuthorisationManageViewLevel)
                {
                case GeneralEnums.InternalSearchLevelEnum.Company:
                    if (view.OfferDetails.ListingOriginatorCompanyId != returnedAuthorisationId)
                    {
                        displayCounterButton = false;
                    }
                    break;

                case GeneralEnums.InternalSearchLevelEnum.Branch:
                    if (view.OfferDetails.ListingOriginatorBranchId != returnedAuthorisationId)
                    {
                        displayCounterButton = false;
                    }
                    break;

                case GeneralEnums.InternalSearchLevelEnum.User:
                    if (view.OfferDetails.ListingOriginatorAppUserId != returnedAuthorisationId)
                    {
                        displayCounterButton = false;
                    }
                    break;

                case GeneralEnums.InternalSearchLevelEnum.Group:      //LSLSLS  TO BE DONE WHEN GROUPS ADDED
                    break;
                }
            }
        }
Exemple #13
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;
                }
            }
        }
Exemple #14
0
        public static List <AvailableListingGeneralInfoView> GetAllAvailableListingsGeneralInfoView(ApplicationDbContext db, IPrincipal user)
        {
            List <AvailableListingGeneralInfoView> allAvailableListingsGeneralInfoView = new List <AvailableListingGeneralInfoView>();

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

            List <AvailableListing> allAvailableListings = AvailableListingHelpers.GetAllGeneralInfoFilteredAvailableListings(db, appUser.AppUserId);

            foreach (AvailableListing availableListing in allAvailableListings)
            {
                //Find any related offers
                Offer   offer    = OfferHelpers.GetOfferForListingAndUser(db, availableListing.ListingId, appUser.AppUserId);
                decimal offerQty = 0M;
                if (offer != null)
                {
                    offerQty = offer.CurrentOfferQuantity;
                }

                bool userBlocked    = false;
                bool branchBlocked  = false;
                bool companyBlocked = false;

                BlockHelpers.GetBlocksForAllTypesForSpecificOfBy(db, availableListing.ListingOriginatorAppUserId, appUser.AppUserId, availableListing.ListingOriginatorBranchId, currentBranch.BranchId, availableListing.ListingOriginatorCompanyId, currentBranch.CompanyId, out userBlocked, out branchBlocked, out companyBlocked);

                bool userMatchedOwner    = false;
                bool branchMatchedOwner  = false;
                bool companyMatchedOwner = false;

                if (currentBranch.CompanyId == availableListing.ListingOriginatorCompanyId)
                {
                    companyMatchedOwner = true;
                }
                if (currentBranch.BranchId == availableListing.ListingOriginatorBranchId)
                {
                    branchMatchedOwner = true;
                }
                if (appUser.AppUserId == availableListing.ListingOriginatorAppUserId)
                {
                    userMatchedOwner = true;
                }

                Company company = CompanyHelpers.GetCompany(db, availableListing.ListingOriginatorCompanyId);

                AvailableListingGeneralInfoView AvailableListingGeneralInfoView = new AvailableListingGeneralInfoView()
                {
                    AvailableListing        = availableListing,
                    OfferQuantity           = offerQty,
                    AllowBranchTrading      = company.AllowBranchTrading,
                    UserLevelBlock          = userBlocked,
                    BranchLevelBlock        = branchBlocked,
                    CompanyLevelBlock       = companyBlocked,
                    DisplayBlocks           = settings.AvailableListingGeneralInfoDisplayBlockedListings,
                    CompanyLevelOwner       = companyMatchedOwner,
                    DisplayMyCompanyRecords = settings.AvailableListingGeneralInfoDisplayMyUserListings,
                    BranchLevelOwner        = branchMatchedOwner,
                    DisplayMyBranchRecords  = settings.AvailableListingGeneralInfoDisplayMyBranchListings,
                    UserLevelOwner          = userMatchedOwner,
                    DisplayMyRecords        = settings.AvailableListingGeneralInfoDisplayMyUserListings
                };

                allAvailableListingsGeneralInfoView.Add(AvailableListingGeneralInfoView);
            }

            return(allAvailableListingsGeneralInfoView);
        }
Exemple #15
0
        public static AppUserEditView GetAppUserEditViewForUser(ApplicationDbContext db, AppUser appUserDetails)
        {
            Branch     branch     = BranchHelpers.GetBranch(db, appUserDetails.CurrentBranchId);
            BranchUser branchUser = BranchUserHelpers.GetBranchUser(db, appUserDetails.AppUserId, appUserDetails.CurrentBranchId);

            AppUserSettings appUserSettings = AppUserSettingsHelpers.GetAppUserSettingsForUser(db, appUserDetails.AppUserId);

            AppUserEditView view = new AppUserEditView()
            {
                AppUserId                                           = appUserDetails.AppUserId,
                FirstName                                           = appUserDetails.FirstName,
                LastName                                            = appUserDetails.LastName,
                EntityStatus                                        = appUserDetails.EntityStatus,
                PrivacyLevel                                        = appUserDetails.PrivacyLevel,
                SelectedBranchId                                    = appUserDetails.CurrentBranchId,
                UserRole                                            = branchUser.UserRole,
                AppUserSettingsId                                   = appUserSettings.AppUserSettingsId,
                BranchName                                          = branch.BranchName,
                BranchBusinessType                                  = branch.BusinessType,
                BranchAddressLine1                                  = branch.AddressLine1,
                BranchAddressLine2                                  = branch.AddressLine2,
                BranchAddressLine3                                  = branch.AddressLine3,
                BranchAddressTownCity                               = branch.AddressTownCity,
                BranchAddressCounty                                 = branch.AddressCounty,
                BranchAddressPostcode                               = branch.AddressPostcode,
                CampaignDashboardMaxDistance                        = appUserSettings.CampaignDashboardMaxDistance,
                CampaignDashboardMaxAge                             = appUserSettings.CampaignDashboardMaxAge,
                RequiredListingDashboardMaxDistance                 = appUserSettings.RequiredListingDashboardMaxDistance,
                RequiredListingDashboardMaxAge                      = appUserSettings.RequiredListingDashboardMaxAge,
                AvailableListingDashboardMaxDistance                = appUserSettings.AvailableListingDashboardMaxDistance,
                AvailableListingDashboardMaxAge                     = appUserSettings.AvailableListingDashboardMaxAge,
                CampaignDashboardExternalSelectionLevel             = appUserSettings.CampaignDashboardExternalSelectionLevel,
                RequiredListingDashboardExternalSelectionLevel      = appUserSettings.RequiredListingDashboardExternalSelectionLevel,
                AvailableListingDashboardExternalSelectionLevel     = appUserSettings.AvailableListingDashboardExternalSelectionLevel,
                CampaignGeneralInfoDisplayMyUserListings            = appUserSettings.CampaignGeneralInfoDisplayMyUserListings,
                CampaignGeneralInfoDisplayMyBranchListings          = appUserSettings.CampaignGeneralInfoDisplayMyBranchListings,
                CampaignGeneralInfoDisplayMyCompanyListings         = appUserSettings.CampaignGeneralInfoDisplayMyCompanyListings,
                CampaignGeneralInfoDisplayBlockedListings           = appUserSettings.CampaignGeneralInfoDisplayBlockedListings,
                CampaignGeneralInfoMaxDistance                      = appUserSettings.CampaignGeneralInfoMaxDistance,
                RequiredListingGeneralInfoDisplayMyUserListings     = appUserSettings.RequiredListingGeneralInfoDisplayMyUserListings,
                RequiredListingGeneralInfoDisplayMyBranchListings   = appUserSettings.RequiredListingGeneralInfoDisplayMyBranchListings,
                RequiredListingGeneralInfoDisplayMyCompanyListings  = appUserSettings.RequiredListingGeneralInfoDisplayMyCompanyListings,
                RequiredListingGeneralInfoDisplayBlockedListings    = appUserSettings.RequiredListingGeneralInfoDisplayBlockedListings,
                RequiredListingGeneralInfoMaxDistance               = appUserSettings.RequiredListingGeneralInfoMaxDistance,
                AvailableListingGeneralInfoDisplayMyUserListings    = appUserSettings.AvailableListingGeneralInfoDisplayMyUserListings,
                AvailableListingGeneralInfoDisplayMyBranchListings  = appUserSettings.AvailableListingGeneralInfoDisplayMyBranchListings,
                AvailableListingGeneralInfoDisplayMyCompanyListings = appUserSettings.AvailableListingGeneralInfoDisplayMyCompanyListings,
                AvailableListingGeneralInfoDisplayBlockedListings   = appUserSettings.AvailableListingGeneralInfoDisplayBlockedListings,
                AvailableListingGeneralInfoMaxDistance              = appUserSettings.AvailableListingGeneralInfoMaxDistance,
                CampaignManageViewInternalSelectionLevel            = appUserSettings.CampaignManageViewInternalSelectionLevel,
                RequiredListingManageViewInternalSelectionLevel     = appUserSettings.RequiredListingManageViewInternalSelectionLevel,
                AvailableListingManageViewInternalSelectionLevel    = appUserSettings.AvailableListingManageViewInternalSelectionLevel,
                OffersManageViewInternalSelectionLevel              = appUserSettings.OffersManageViewInternalSelectionLevel,
                OffersAcceptedAuthorisationManageViewLevel          = appUserSettings.OffersAcceptedAuthorisationManageViewLevel,
                OffersRejectedAuthorisationManageViewLevel          = appUserSettings.OffersRejectedAuthorisationManageViewLevel,
                OffersReturnedAuthorisationManageViewLevel          = appUserSettings.OffersReturnedAuthorisationManageViewLevel,
                OrdersManageViewInternalSelectionLevel              = appUserSettings.OrdersManageViewInternalSelectionLevel,
                OrdersDespatchedAuthorisationManageViewLevel        = appUserSettings.OrdersDespatchedAuthorisationManageViewLevel,
                OrdersDeliveredAuthorisationManageViewLevel         = appUserSettings.OrdersDeliveredAuthorisationManageViewLevel,
                OrdersCollectedAuthorisationManageViewLevel         = appUserSettings.OrdersCollectedAuthorisationManageViewLevel,
                OrdersClosedAuthorisationManageViewLevel            = appUserSettings.OrdersClosedAuthorisationManageViewLevel,
                CampaignGeneralInfoExternalSelectionLevel           = appUserSettings.CampaignGeneralInfoExternalSelectionLevel,
                RequiredListingGeneralInfoExternalSelectionLevel    = appUserSettings.RequiredListingGeneralInfoExternalSelectionLevel,
                AvailableListingGeneralInfoExternalSelectionLevel   = appUserSettings.AvailableListingGeneralInfoExternalSelectionLevel,
                GroupListViewsForUserOnly                           = GroupViewHelpers.GetGroupEditViewForForUserOnly(db, appUserDetails.AppUserId),
                UserFriendListView                                  = FriendViewHelpers.GetFriendViewByType(db, appUserDetails.AppUserId, LevelEnum.User),
                UserBranchFriendListView                            = FriendViewHelpers.GetFriendViewByType(db, appUserDetails.AppUserId, LevelEnum.Branch),
                UserCompanyFriendListView                           = FriendViewHelpers.GetFriendViewByType(db, appUserDetails.AppUserId, LevelEnum.Company),
                UserBlockListView                                   = BlockViewHelpers.GetBlockViewByType(db, appUserDetails.AppUserId, LevelEnum.User),
                UserBranchBlockListView                             = BlockViewHelpers.GetBlockViewByType(db, appUserDetails.AppUserId, LevelEnum.Branch),
                UserCompanyBlockListView                            = BlockViewHelpers.GetBlockViewByType(db, appUserDetails.AppUserId, LevelEnum.Company)
            };

            return(view);
        }