Beispiel #1
0
        public static GroupAddView GetGroupAddView(ApplicationDbContext db, LevelEnum?level, Guid?ofReferenceId, Guid?byReferenceId, Guid?byAppUserId, Guid appUserId)
        {
            //Build a list of companies/branches/users from level if set
            List <GroupAddMemberView> members = new List <GroupAddMemberView>();
            GroupAddView view = new GroupAddView();

            if (level != null)  //Build a list of users for this view
            {
                switch (level.Value)
                {
                case LevelEnum.Company:
                    List <Company> companies = CompanyHelpers.GetAllCompaniesForGroupForUser(db, appUserId);
                    foreach (Company company in companies)
                    {
                        members.Add(GroupMemberViewHelpers.CreateGroupAddMemberViewMember(db, false, company.CompanyId, company.CompanyName));
                    }
                    break;

                case LevelEnum.Branch:
                    List <Branch> branches = BranchHelpers.GetAllBranchesForGroupForUser(db, appUserId);
                    foreach (Branch branch in branches)
                    {
                        members.Add(GroupMemberViewHelpers.CreateGroupAddMemberViewMember(db, false, branch.BranchId, branch.BranchName + ", " + branch.AddressTownCity));
                    }
                    break;

                case LevelEnum.User:
                    List <AppUser> users = AppUserHelpers.GetAllAppUsersForGroupForUser(db, appUserId);
                    foreach (AppUser user in users)
                    {
                        members.Add(GroupMemberViewHelpers.CreateGroupAddMemberViewMember(db, false, user.AppUserId, user.FirstName + " " + user.LastName));
                    }
                    break;
                }

                view.Type         = level.Value;
                view.scratchEntry = false;
                view.Members      = members;
            }
            else //return blank view with blank users as this is new from scratch
            {
                view.scratchEntry = true;  //this  will be used in view to stop the changing fo the 'type' field.

                //build members as User as this is the default
                List <AppUser> users = AppUserHelpers.GetAllAppUsersForGroupForUser(db, appUserId);
                foreach (AppUser user in users)
                {
                    members.Add(GroupMemberViewHelpers.CreateGroupAddMemberViewMember(db, false, user.AppUserId, user.FirstName + " " + user.LastName));
                }

                view.Members = members;
            }

            return(view);
        }
Beispiel #2
0
        public static GroupAddView GetGroupAddView(ApplicationDbContext db, string groupName, string level, IPrincipal user)
        {
            List <GroupAddMemberView> members = new List <GroupAddMemberView>();
            GroupAddView view      = new GroupAddView();
            LevelEnum    levelEnum = LevelEnum.User;

            switch (level)
            {
            case "Company":
                levelEnum = LevelEnum.Company;
                List <Company> companies = CompanyHelpers.GetAllCompaniesForGroupForUser(db, AppUserHelpers.GetAppUserIdFromUser(user));
                foreach (Company company in companies)
                {
                    members.Add(GroupMemberViewHelpers.CreateGroupAddMemberViewMember(db, false, company.CompanyId, company.CompanyName));
                }
                break;

            case "Branch":
                levelEnum = LevelEnum.Branch;
                List <Branch> branches = BranchHelpers.GetAllBranchesForGroupForUser(db, AppUserHelpers.GetAppUserIdFromUser(user));
                foreach (Branch branch in branches)
                {
                    members.Add(GroupMemberViewHelpers.CreateGroupAddMemberViewMember(db, false, branch.BranchId, branch.BranchName + ", " + branch.AddressTownCity));
                }
                break;

            case "User":
                levelEnum = LevelEnum.User;
                List <AppUser> users = AppUserHelpers.GetAllAppUsersForGroupForUser(db, AppUserHelpers.GetAppUserIdFromUser(user));
                foreach (AppUser appUser in users)
                {
                    members.Add(GroupMemberViewHelpers.CreateGroupAddMemberViewMember(db, false, appUser.AppUserId, appUser.FirstName + " " + appUser.LastName));
                }
                break;
            }

            view.Name         = groupName;
            view.Type         = levelEnum;
            view.scratchEntry = true; //this only comes from the scratch entry values
            view.Members      = members;

            return(view);
        }