예제 #1
0
        public bool SetRoleUser(SetRoleViewModel model)
        {
            aService.ClearRolesUser(model.UserId);
            foreach (int id in model.RoleId)
            {
                Accessment assess = new Accessment();
                assess.UserId       = model.UserId;
                assess.RoleId       = id;
                assess.AccessedDate = DateTime.Now;
                assess.ExpireDate   = DateTime.Now.AddYears(1);
                aService.SetRoleUser(assess);
            }
            User         user         = cService.GetUser(model.UserId);
            Notification notification = new Notification();

            notification.AuthorId    = _currentUserId;
            notification.CreatedDate = DateTime.Now;
            notification.Content     = string.Join(",", user.Assessments.Select(u => u.Role.Name));
            notification.Seen        = false;
            notification.Type        = NotificationSettingEnum.Banned;
            notification.UserId      = model.UserId;
            notification.Link        = Url.Action("BannedPage", "Account");
            cService.AddNotification(notification);

            using (RealTimeService rService = new RealTimeService(new CPMathHubModelContainer(), notification.UserId))
            {
                IEnumerable <string> connectionIds = RealTimeHub.Connections.GetConnections(notification.UserId);
                foreach (string conId in connectionIds)
                {
                    _hub.Clients.Client(conId).notifyNewActivity(rService.CountNewActivityNotification());
                }
            }
            return(true);
        }
예제 #2
0
        public ActionResult SetRole(int id)
        {
            SetRoleViewModel ur = new SetRoleViewModel();

            ur.UserModel = userInfoBll.Select(id);
            //ViewData["UserInfo"]= userInfoBll.Select(id);
            ur.RoleModels = roleInfoBll.Select(u => u.IsDelete == false).ToList();
            //ViewData.Model = roleInfoBll.Select(u => u.IsDelete == false).ToList();
            ViewData.Model = ur;
            return(View());
        }
예제 #3
0
        public async Task <IActionResult> SetRole([FromBody] SetRoleViewModel model)
        {
            if (ModelState.IsValid)
            {
                var userVeri = await userManager.FindByNameAsync(model.userName);

                if (userVeri != null)
                {
                    if (await roleManager.RoleExistsAsync(model.roleName))
                    {
                        await userManager.AddToRoleAsync(userVeri, model.roleName);

                        return(Ok());
                    }
                }
            }
            return(BadRequest());
        }
예제 #4
0
        public async Task <IActionResult> Edit(string userId)
        {
            var user = await _userManager.FindByIdAsync(userId);

            if (user != null)
            {
                var userRoles = await _userManager.GetRolesAsync(user);

                var allRoles = _roleManager.Roles.ToList();
                var model    = new SetRoleViewModel
                {
                    UserId    = user.Id,
                    UserName  = user.UserName,
                    UserRoles = userRoles,
                    AllRoles  = allRoles
                };
                return(View(model));
            }

            return(NotFound());
        }
예제 #5
0
        public ActionResult SetRole()
        {
            List <SetRoleViewModel> vm = new List <ViewModels.SetRoleViewModel>();

            using (var db = new ApplicationDbContext())
            {
                var allUsers = db.Users.ToList();
                foreach (var item in allUsers)
                {
                    SetRoleViewModel user = new SetRoleViewModel();
                    user.Role = new List <string>();

                    foreach (var role in item.Roles)
                    {
                        user.Role.Add(role.Role.Name);
                    }
                    user.Id       = item.Id;
                    user.UserName = item.UserName;
                    vm.Add(user);
                }
            }

            return(View(vm));
        }