예제 #1
0
        public ActionResult AddUserToExamGroup(
            [DataSourceRequest] DataSourceRequest request,
            int id,
            string userId)
        {
            var examGroup = this.examGroupsData.GetById(id);
            var user      = this.usersData.GetById(userId);

            if (examGroup.ContestId == null)
            {
                this.ModelState.AddModelError(string.Empty, Resource.Cannot_add_users);
                return(this.GridOperation(request, null));
            }

            if (!this.UserHasContestRights(examGroup.ContestId.Value))
            {
                this.ModelState.AddModelError(string.Empty, GeneralResource.No_privileges_message);
                return(this.GridOperation(request, null));
            }

            examGroup.Users.Add(user);
            this.examGroupsData.Update(examGroup);

            var result = new DetailModelType
            {
                UserId    = user.Id,
                Username  = user.UserName,
                FirstName = user.UserSettings.FirstName,
                LastName  = user.UserSettings.LastName,
                Email     = user.Email
            };

            return(this.Json(new[] { result }.ToDataSourceResult(request), JsonRequestBehavior.AllowGet));
        }
예제 #2
0
        public ActionResult AddUserToRole([DataSourceRequest] DataSourceRequest request, string id, string userId)
        {
            var user = this.Data.Users.GetById(userId);
            var role = this.Data.Roles.All().FirstOrDefault(r => r.Id == id);

            user.Roles.Add(new IdentityUserRole {
                RoleId = role.Id, UserId = userId
            });
            this.Data.SaveChanges();

            var result = new DetailModelType
            {
                UserId    = user.Id,
                Username  = user.UserName,
                FirstName = user.UserSettings.FirstName,
                LastName  = user.UserSettings.LastName,
                Email     = user.Email
            };

            return(this.Json(new[] { result }.ToDataSourceResult(request), JsonRequestBehavior.AllowGet));
        }
예제 #3
0
        public ActionResult RemoveUserFromExamGroup(
            [DataSourceRequest] DataSourceRequest request,
            DetailModelType model,
            int id)
        {
            var contestId = this.examGroupsData.GetContestIdById(id);

            if (!contestId.HasValue)
            {
                this.ModelState.AddModelError(string.Empty, Resource.Cannot_remove_users);
                return(this.RedirectToAction <ExamGroupsController>(c => c.Index()));
            }

            if (!this.UserHasContestRights(contestId.Value))
            {
                this.TempData.AddDangerMessage(GeneralResource.No_privileges_message);
                return(this.RedirectToAction <ExamGroupsController>(c => c.Index()));
            }

            this.examGroupsData.RemoveUserByIdAndUser(id, model.UserId);
            return(this.GridOperation(request, model));
        }
예제 #4
0
        public ActionResult DeleteUserFromRole([DataSourceRequest] DataSourceRequest request, string id, DetailModelType model)
        {
            var user = this.Data.Users.GetById(model.UserId);

            var roleStore   = new RoleStore <IdentityRole>();
            var roleManager = new RoleManager <IdentityRole>(roleStore);
            var role        = roleManager.Roles.FirstOrDefault(r => r.Id == id);

            if (role != null && role.Name == GlobalConstants.LecturerRoleName)
            {
                this.Data.LecturersInContests.Delete(x => x.LecturerId == model.UserId);
                this.Data.LecturersInContestCategories.Delete(x => x.LecturerId == model.UserId);
            }

            var userRole = user.Roles.FirstOrDefault(r => r.RoleId == id);

            user.Roles.Remove(userRole);
            this.Data.SaveChanges();

            return(this.Json(this.ModelState.ToDataSourceResult()));
        }