示例#1
0
 private static List<Role> AddTenRoles()
 {
     List<Role> roleCollection = new List<Role>();
     for (int i = 0; i < 9; i++)
     {
         Role role = new Role();
         roleCollection.Add(role);
     }
     return roleCollection;
 }
 public override void CreateRole(string roleName)
 {
     if (!string.IsNullOrEmpty(roleName))
     {
         using (DataContext Context = new DataContext())
         {
             Role Role = null;
             Role = Context.Roles.FirstOrDefault(Rl => Rl.RoleName == roleName);
             if (Role == null)
             {
                 Role NewRole = new Role
                 {
                     Id = Guid.NewGuid(),
                     RoleName = roleName
                 };
                 Context.Roles.Add(NewRole);
                 Context.SaveChanges();
             }
         }
     }
 }
示例#3
0
        //create  a new role with a given name
        public override void CreateRole(string rolename)
        {
            if (rolename.Contains(","))
                throw new ArgumentException("Role names cannot contain commas.");

            if (RoleExists(rolename))
                throw new ProviderException("Role name already exists.");

            try {
                var role = new Role { ApplicationName = ApplicationName, RoleName = rolename };
                roles.Update(role);
                roles.SaveChanges();
            } catch (Exception ex) {
                if (WriteExceptionsToEventLog)
                    WriteToEventLog(ex, "CreateRole");
                else
                    throw;
            }
        }
示例#4
0
文件: User.cs 项目: vbre/CS2_Project
 public User()
 {
     PersonalInfo = new PersonalInfo();
     Role = new Role();
 }
示例#5
0
 public virtual void RemoveRole(Role role)
 {
     role.UsersInRole.Remove(this);
     Roles.Remove(role);
 }
示例#6
0
 public virtual void AddRole(Role role)
 {
     role.UsersInRole.Add(this);
     Roles.Add(role);
 }