Exemple #1
0
        // GET: GroupUser/Create
        public async Task <ActionResult> Create(string groupId)
        {
            string accessToken     = Session["MicrosoftAccessToken"] as string;
            var    roleTypeService = new RoleTypeService(accessToken);
            var    allRoleTypes    = await roleTypeService.GetAllRoleTypes();

            var defaultRole = allRoleTypes.Single(r => r.RoleKey == (int)RoleTypeEnum.Viewer);

            ViewBag.RoleTypeId = new SelectList(allRoleTypes, "Id", "RoleName", defaultRole.Id);
            ViewBag.GroupId    = groupId;

            GroupService groupService = new GroupService(accessToken);
            string       groupName    = await groupService.GroupNameByGroupId(groupId);

            if (await AccessAdmin(groupId) && !(groupName.Contains("Default group for user")))
            {
                return(View());
            }
            else
            {
                return(View("AccessDenied"));
            }

            return(View());
        }
Exemple #2
0
        // GET: GroupUser
        public async Task <ActionResult> Index(string groupId)
        {
            string accessToken      = Session["MicrosoftAccessToken"] as string;
            var    roleTypeService  = new RoleTypeService(accessToken);
            var    userDataService  = new UserService(accessToken);
            var    userGroupService = new UserGroupService(accessToken);

            var allRoleTypes = await roleTypeService.GetAllRoleTypes();

            var usersFromGroup = await userDataService.GetUsersFromGroup(groupId);

            List <GroupUserModel> guModelsList = new List <GroupUserModel>();

            foreach (var user in usersFromGroup)
            {
                var userGroup = await userGroupService.GetUserGroup(user.Id, groupId);

                GroupUserModel guModel = new GroupUserModel();
                guModel.UserGroupId = userGroup.Id;
                guModel.UserEmail   = user.Email;
                guModel.RoleTypeId  = userGroup.RoleTypeId;
                guModel.RoleName    = allRoleTypes.Single(r => r.Id == userGroup.RoleTypeId).RoleName;
                guModelsList.Add(guModel);
            }

            ViewBag.GroupId = groupId;
            return(View(guModelsList));
        }
Exemple #3
0
        // GET: GroupUser/Delete/5
        public async Task <ActionResult> Delete(string userGroupId)
        {
            string accessToken      = Session["MicrosoftAccessToken"] as string;
            var    roleTypeService  = new RoleTypeService(accessToken);
            var    userService      = new UserService(accessToken);
            var    userGroupService = new UserGroupService(accessToken);

            var allRoleTypes = await roleTypeService.GetAllRoleTypes();

            var userGroup = await userGroupService.GetUserGroupById(userGroupId);

            var user = await userService.GetUserById(userGroup.UserId);

            GroupUserModel guModel = new GroupUserModel();

            guModel.UserEmail   = user.Email;
            guModel.RoleTypeId  = userGroup.RoleTypeId;
            guModel.RoleName    = allRoleTypes.Single(r => r.Id == userGroup.RoleTypeId).RoleName;
            guModel.UserGroupId = userGroup.Id;

            ViewBag.GroupId = userGroup.GroupId;

            GroupService groupService = new GroupService(accessToken);
            string       groupName    = await groupService.GroupNameByGroupId(userGroup.GroupId);

            if (await AccessAdmin(userGroup.GroupId) && !userGroup.IsUserDefaultGroup)
            {
                return(View(guModel));
            }
            else
            {
                return(View("AccessDenied"));
            }
        }
Exemple #4
0
        public async Task <ActionResult> Create(string groupId, GroupUserModel groupUserModel)
        {
            try
            {
                string accessToken = Session["MicrosoftAccessToken"] as string;
                var    userService = new UserService(accessToken);
                var    user        = await userService.GetUsersByEmail(groupUserModel.UserEmail);

                if (user == null)
                {
                    ModelState.AddModelError("Error", "User with this email does not exist!");
                    ViewBag.Error = TempData["Error"];
                    var roleTypeService = new RoleTypeService(accessToken);
                    var allRoleTypes    = await roleTypeService.GetAllRoleTypes();

                    var defaultRole = allRoleTypes.Single(r => r.RoleKey == (int)RoleTypeEnum.Viewer);
                    ViewBag.RoleTypeId = new SelectList(allRoleTypes, "Id", "RoleName", defaultRole.Id);
                    ViewBag.GroupId    = groupId;
                    return(View(groupUserModel));
                }
                else
                {
                    UserGroup userGroup = new UserGroup
                    {
                        Id                 = Guid.NewGuid().ToString(),
                        GroupId            = groupId,
                        RoleTypeId         = groupUserModel.RoleTypeId,
                        UserId             = user.Id,
                        IsUserDefaultGroup = false
                    };

                    var userGroupService = new UserGroupService(accessToken);
                    await userGroupService.Insert(userGroup);

                    return(RedirectToAction("Index", new { groupId }));
                }
            }
            catch
            {
                return(View());
            }
        }
Exemple #5
0
        // GET: GroupUser/Details/5
        public async Task <ActionResult> Details(string userGroupId)
        {
            string accessToken      = Session["MicrosoftAccessToken"] as string;
            var    roleTypeService  = new RoleTypeService(accessToken);
            var    userService      = new UserService(accessToken);
            var    userGroupService = new UserGroupService(accessToken);

            var allRoleTypes = await roleTypeService.GetAllRoleTypes();

            var userGroup = await userGroupService.GetUserGroupById(userGroupId);

            var user = await userService.GetUserById(userGroup.UserId);

            GroupUserModel guModel = new GroupUserModel();

            guModel.UserEmail   = user.Email;
            guModel.RoleTypeId  = userGroup.RoleTypeId;
            guModel.RoleName    = allRoleTypes.Single(r => r.Id == userGroup.RoleTypeId).RoleName;
            guModel.UserGroupId = userGroup.Id;

            ViewBag.GroupId = userGroup.GroupId;
            return(View(guModel));
        }