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 UserInRoleAdministrationViewModel
            {
                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));
        }
Beispiel #2
0
        public ActionResult AddUserToRole([DataSourceRequest] DataSourceRequest request, string id, string userId)
        {
            var user = this.userAdministrationService.Get(userId);
            var role = this.userRoleAdministrationService.Read().FirstOrDefault(r => r.Id == id);

            //var userToRole = new IdentityUserRole();

            //userToRole.RoleId = role.Id;
            //userToRole.UserId = userId;

            this.userAdministrationService.AddUserToRole("66305dc8-0198-4226-af02-c80520118c88", "Administrator");

            var result = new UserInRoleAdministrationViewModel
            {
                Id        = user.Id,
                UserName  = user.UserName,
                FirstName = user.FirstName,
                LastName  = user.LastName,
                Email     = user.Email
            };

            return(this.Json(new[] { result }.ToDataSourceResult(request), JsonRequestBehavior.AllowGet));
        }