示例#1
0
        public static Group CreateGroupFromGroupAddView(GroupAddView view, IPrincipal user)
        {
            ApplicationDbContext db = new ApplicationDbContext();
            Group group             = CreateGroupFromGroupAddView(db, view, user);

            db.Dispose();
            return(group);
        }
示例#2
0
        public static List <GroupMember> CreateGroupMembersFromGroupAddView(GroupAddView view, Group group)
        {
            ApplicationDbContext db   = new ApplicationDbContext();
            List <GroupMember>   list = CreateGroupMembersFromGroupAddView(db, view, group);

            db.Dispose();
            return(list);
        }
示例#3
0
        public static GroupAddView GetGroupAddView(string groupName, string level, IPrincipal user)
        {
            ApplicationDbContext db   = new ApplicationDbContext();
            GroupAddView         view = GetGroupAddView(db, groupName, level, user);

            db.Dispose();
            return(view);
        }
示例#4
0
        public static GroupAddView GetGroupAddView(LevelEnum?level, Guid?ofReferenceId, Guid?byReferenceId, Guid?byAppUserId, Guid appUserId)
        {
            ApplicationDbContext db   = new ApplicationDbContext();
            GroupAddView         view = GetGroupAddView(db, level, ofReferenceId, byReferenceId, byAppUserId, appUserId);

            db.Dispose();
            return(view);
        }
示例#5
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);
        }
示例#6
0
        public ActionResult Create(GroupAddView model)
        {
            if (ModelState.IsValid)
            {
                GroupHelpers.CreateGroupFromGroupAddView(db, model, User);

                return(RedirectToAction("Index"));
            }

            return(View(model));
        }
示例#7
0
        // GET: Groups/Create
        //first 4 variables come from the +Button on the general info screens.
        public ActionResult Create(LevelEnum?level, Guid?ofReferenceId, Guid?byReferenceId, Guid?byAppUserId, Guid?appUserId)
        {
            if (appUserId == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            GroupAddView model = GroupViewHelpers.GetGroupAddView(level, ofReferenceId, byReferenceId, byAppUserId, appUserId.Value);

            return(View(model));
        }
示例#8
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);
        }
示例#9
0
        public static Group CreateGroupFromGroupAddView(ApplicationDbContext db, GroupAddView view, IPrincipal user)
        {
            Group group = new Group()
            {
                GroupId                  = Guid.NewGuid(),
                Name                     = view.Name,
                Type                     = view.Type,
                VisibilityLevel          = view.VisibilityLevel,
                InviteLevel              = view.InviteLevel,
                AcceptanceLevel          = view.AcceptanceLevel,
                GroupOriginatorAppUserId = AppUserHelpers.GetAppUserIdFromUser(user),
                GroupOriginatorDateTime  = DateTime.Now
            };

            db.Groups.Add(group);
            db.SaveChanges();

            GroupViewHelpers.CreateGroupMembersFromGroupAddView(db, view, group);

            return(group);
        }
示例#10
0
        public static List <GroupMember> CreateGroupMembersFromGroupAddView(ApplicationDbContext db, GroupAddView view, Group group)
        {
            List <GroupMember> members = new List <GroupMember>();

            foreach (GroupAddMemberView member in view.Members)
            {
                if (member.SelectedUser)
                {
                    if (view.AcceptanceLevel == GroupInviteAcceptanceLevelEnum.Automatic)
                    {
                        members.Add(CreateGroupMember(db, group, member.ReferenceId, GroupMemberStatusEnum.Accepted));
                    }
                    else
                    {
                        members.Add(CreateGroupMember(db, group, member.ReferenceId, GroupMemberStatusEnum.Awaiting));
                    }
                }
            }

            return(members);
        }
示例#11
0
        public ActionResult GetMemberList(string groupName, string memberType)
        {
            GroupAddView model = GroupViewHelpers.GetGroupAddView(groupName, memberType, User);

            return(PartialView("AddGroupMembers", model));
        }