public void CreateRoles() { var roleNames = System.Enum.GetNames(typeof(RoleName)); foreach (var roleName in roleNames) { CreateRole(roleName); } MtfDatabase.SaveChanges(); }
public void RemoveUserFromRole(User user, Role role) { var userRole = MtfDatabase.UserRoles.Find(user.Id, role.Id); if (userRole != null) { MtfDatabase.UserRoles.Remove(userRole); MtfDatabase.SaveChanges(); PermissionHandler.SetPrincipals(user); } }
public void AddUserToRole(User user, Role role) { var userRole = MtfDatabase.UserRoles.Find(user.Id, role.Id); if (userRole == null) { MtfDatabase.UserRoles.Add(new UserRole { User = user, Role = role }); MtfDatabase.SaveChanges(); PermissionHandler.SetPrincipals(user); } }
public User GetOrCreate(string name) { var result = Get(name); if (result != null) { return(result); } result = new User { Name = name }; MtfDatabase.Users.Add(result); optionsRepository.Value.CreateDefaultOptionsForUser(result); userRolesRepository.Value.CreateDefaultRolesForUser(result); PermissionHandler.SetPrincipals(result); MtfDatabase.SaveChanges(); return(result); }
public void CreateOption(Option option) { MtfDatabase.Options.Add(option); MtfDatabase.SaveChanges(); }