Exemplo n.º 1
0
        //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);
        }
Exemplo n.º 2
0
        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);
        }
Exemplo n.º 3
0
        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);
        }
Exemplo n.º 4
0
        public static Block CreateBlock(ApplicationDbContext db, LevelEnum level, Guid ofReferenceId, Guid byReferenceId, Guid byAppUserId)
        {
            //Remove Friends for those to be blocked
            FriendHelpers.RemoveFriendItemsDueToBlock(db, level, ofReferenceId, byReferenceId, byAppUserId);

            //LSLSLS Remove from Group if there (at the correct level)


            Block block = new Block()
            {
                BlockId         = Guid.NewGuid(),
                Type            = level,
                BlockedOfId     = ofReferenceId,
                BlockedById     = byReferenceId,
                BlockedByUserId = byAppUserId,
                BlockedOn       = DateTime.Now
            };

            db.Blocks.Add(block);
            db.SaveChanges();

            return(block);
        }
Exemplo n.º 5
0
        public static List <FriendView> GetFriendViewByType(ApplicationDbContext db, Guid appUserId, LevelEnum type)
        {
            List <FriendView> list = new List <FriendView>();

            List <Friend> friendList = null;

            //Depending on type passed through will depend on what level of friends we are collecting
            switch (type)
            {
            case LevelEnum.User:
                friendList = FriendHelpers.GetFriendsCreatedByUser(db, appUserId);
                break;

            case LevelEnum.Branch:
                friendList = FriendHelpers.GetFriendsCreatedByUserBranches(db, appUserId);
                break;

            case LevelEnum.Company:
                friendList = FriendHelpers.GetFriendsCreatedByUserCompany(db, appUserId);
                break;
            }

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

                switch (friend.Type)
                {
                case LevelEnum.User:
                    nameBy = AppUserHelpers.GetAppUserName(db, friend.RequestedById);
                    nameOn = AppUserHelpers.GetAppUserName(db, friend.RequestedOfId);
                    break;

                case LevelEnum.Branch:
                    nameBy = BranchHelpers.GetBranchNameTownPostCode(db, friend.RequestedById);
                    nameOn = BranchHelpers.GetBranchNameTownPostCode(db, friend.RequestedOfId);
                    break;

                case LevelEnum.Company:
                    nameBy = CompanyHelpers.GetCompanyNameTownPostCode(db, friend.RequestedById);
                    nameOn = CompanyHelpers.GetCompanyNameTownPostCode(db, friend.RequestedOfId);
                    break;
                }

                string friendedByUserName = AppUserHelpers.GetAppUserName(db, friend.RequestedByUserId);

                bool friendedByLoggedInUser = false;

                if (friend.RequestedByUserId == appUserId)
                {
                    friendedByLoggedInUser = true;
                }

                FriendView view = new FriendView()
                {
                    FriendId               = friend.FriendId,
                    Type                   = friend.Type,
                    RequestedByName        = nameBy,
                    RequestedByUserName    = friendedByUserName,
                    RequestedOfName        = nameOn,
                    Status                 = friend.Status,
                    RequestedOn            = friend.RequestedOn,
                    AccceptedOn            = friend.AccceptedOn,
                    RejectedOn             = friend.RequestedOn,
                    ClosedOn               = friend.ClosedOn,
                    ClosedBy               = friend.ClosedBy,
                    FriendedByLoggedInUser = friendedByLoggedInUser
                };

                list.Add(view);
            }

            return(list);
        }