public bool Update(EditRoleViewModel model) { bool res = false; //We have to check if that role exist, if it exist return false else create new role and return true if (_idman.RoleExists(model.RoleName)) res = false; else { _idman.CreateRole(model.RoleName, model.Description); ////Then we move all users from the previous role to the new role //var newrole = ConvertRole(FirstRole(model.RoleName)); //var oldrole = ConvertRole(FirstRole(model.OriginalRoleName)); //var roleUsers = _db.Users.Where(u => u.Roles.Any(r => r.RoleId == oldrole.Name)); //foreach (var user in roleUsers) //{ // _idman.AddUserToRole(user.Id, model.RoleName); //} ////Then we finaly delete the old role and create a new role //_idman.DeleteRole(oldrole.Id); //_idman.CreateRole(newrole.Id, newrole.Description); res = true; } return res; }
public EditRoleViewModel GetRole(string id) { var role = _db.Roles.First(r => r.Name == id); var roleModel = new EditRoleViewModel(ConvertRole(role)); return roleModel; }