Beispiel #1
0
        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);
        }
        //NOTE - SetCompanyButtons, SetBranchButtons, SetUserButtons, must run in that order as the user rely on the branch rely on the company
        //There is also a check on block as if Block is set then no buttons should be shown for that level downwards.
        public static ViewButtons SetCompanyButtons(ApplicationDbContext db, ViewButtons buttons, Guid viewItemcompanyId, Guid currentCompanyId)
        {
            buttons.CompanyBlockButton = !BlockHelpers.IsReferenceBlocked(db, LevelEnum.Company, viewItemcompanyId, currentCompanyId);

            //if company block then do not show company and lower add buttons
            if (!buttons.CompanyBlockButton)
            {
                buttons.CompanyAddFriendButton  = buttons.CompanyBlockButton;
                buttons.CompanyAddToGroupButton = buttons.CompanyBlockButton;
            }
            else
            {
                buttons.CompanyAddFriendButton  = !FriendHelpers.IsReferenceAnActiveFriendRequest(db, LevelEnum.Company, viewItemcompanyId, currentCompanyId);
                buttons.CompanyAddToGroupButton = !GroupHelpers.IsReferenceInGroup(db, LevelEnum.Company, viewItemcompanyId, currentCompanyId);
            }
            return(buttons);
        }
        public static ViewButtons SetUserButtons(ApplicationDbContext db, ViewButtons buttons, Guid viewItemUserId, Guid currentUserId)
        {
            //if the button is hidden at branch level then hide at user level
            if (!buttons.BranchBlockButton)
            {
                buttons.UserBlockButton = buttons.BranchBlockButton;
            }
            else
            {
                buttons.UserBlockButton = !BlockHelpers.IsReferenceBlocked(db, LevelEnum.User, viewItemUserId, currentUserId);
            }

            //If user block then do not show user buttons
            if (!buttons.UserBlockButton)
            {
                buttons.UserAddFriendButton  = buttons.UserBlockButton;
                buttons.UserAddToGroupButton = buttons.UserBlockButton;
            }
            else
            {
                if (!buttons.BranchAddFriendButton)
                {
                    buttons.UserAddFriendButton = buttons.BranchAddFriendButton;
                }
                else
                {
                    buttons.UserAddFriendButton = !FriendHelpers.IsReferenceAnActiveFriendRequest(db, LevelEnum.User, viewItemUserId, currentUserId);
                }

                if (!buttons.BranchAddToGroupButton)
                {
                    buttons.UserAddToGroupButton = buttons.BranchAddToGroupButton;
                }
                else
                {
                    buttons.UserAddToGroupButton = !GroupHelpers.IsReferenceInGroup(db, LevelEnum.User, viewItemUserId, currentUserId);
                }
            }
            return(buttons);
        }
        public static ViewButtons SetBranchButtons(ApplicationDbContext db, ViewButtons buttons, Guid viewItemBranchId, Guid currentBranchId)
        {
            //if the button is hidden at company level then hide at branch level
            if (!buttons.CompanyBlockButton)
            {
                buttons.BranchBlockButton = buttons.CompanyBlockButton;
            }
            else
            {
                buttons.BranchBlockButton = !BlockHelpers.IsReferenceBlocked(db, LevelEnum.Branch, viewItemBranchId, currentBranchId);
            }

            //if branch block then do not show branch and lower add buttons
            if (!buttons.BranchBlockButton)
            {
                buttons.BranchAddFriendButton  = buttons.BranchBlockButton;
                buttons.BranchAddToGroupButton = buttons.BranchBlockButton;
            }
            else
            {
                if (!buttons.CompanyAddFriendButton)
                {
                    buttons.BranchAddFriendButton = buttons.CompanyAddFriendButton;
                }
                else
                {
                    buttons.BranchAddFriendButton = !FriendHelpers.IsReferenceAnActiveFriendRequest(db, LevelEnum.Branch, viewItemBranchId, currentBranchId);
                }

                if (!buttons.CompanyAddToGroupButton)
                {
                    buttons.BranchAddToGroupButton = buttons.CompanyAddToGroupButton;
                }
                else
                {
                    buttons.BranchAddToGroupButton = !GroupHelpers.IsReferenceInGroup(db, LevelEnum.Branch, viewItemBranchId, currentBranchId);
                }
            }
            return(buttons);
        }
Beispiel #5
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);
        }
Beispiel #6
0
        public static List <BlockView> GetBlockViewByType(ApplicationDbContext db, Guid appUserId, LevelEnum type)
        {
            List <BlockView> list = new List <BlockView>();

            List <Block> blockList = null;

            //Depending on type passed through will depend on what level of blocks we are collecting
            switch (type)
            {
            case LevelEnum.User:
                blockList = BlockHelpers.GetBlocksCreatedByUser(db, appUserId);
                break;

            case LevelEnum.Branch:
                blockList = BlockHelpers.GetBlocksCreatedByUserBranches(db, appUserId);
                break;

            case LevelEnum.Company:
                blockList = BlockHelpers.GetBlocksCreatedByUserCompany(db, appUserId);
                break;
            }

            foreach (Block block in blockList)
            {
                //get the user/branch/company names depending on the block type
                string nameBy = "";
                string nameOn = "";

                switch (block.Type)
                {
                case LevelEnum.User:
                    nameBy = AppUserHelpers.GetAppUserName(db, block.BlockedById);
                    nameOn = AppUserHelpers.GetAppUserName(db, block.BlockedOfId);
                    break;

                case LevelEnum.Branch:
                    nameBy = BranchHelpers.GetBranchNameTownPostCode(db, block.BlockedById);
                    nameOn = BranchHelpers.GetBranchNameTownPostCode(db, block.BlockedOfId);
                    break;

                case LevelEnum.Company:
                    nameBy = CompanyHelpers.GetCompanyNameTownPostCode(db, block.BlockedById);
                    nameOn = CompanyHelpers.GetCompanyNameTownPostCode(db, block.BlockedOfId);
                    break;
                }

                string blockedByUserName = AppUserHelpers.GetAppUserName(db, block.BlockedByUserId);

                bool blockedByLoggedInUser = false;

                if (block.BlockedByUserId == appUserId)
                {
                    blockedByLoggedInUser = true;
                }

                BlockView view = new BlockView()
                {
                    BlockId               = block.BlockId,
                    Type                  = block.Type,
                    BlockedByName         = nameBy,
                    BlockedByUserName     = blockedByUserName,
                    BlockedOfName         = nameOn,
                    BlockedOn             = block.BlockedOn,
                    BlockedByLoggedInUser = blockedByLoggedInUser
                };

                list.Add(view);
            }

            return(list);
        }