public void AddUserInRole(string login, string roleName) { var user = GetUserInternal(login, true); var role = GetRoleInternal(roleName, true); if (!role.IsInSchema(user.Schema)) { throw new Exception(String.Format("O papel {0} não faz parte do esquema ao qual o usuário {1} pertence.", roleName, login)); } Sync(() => { if (!user.IsInRole(role)) { var relation = new UserRoleRelation() { Login = user.Login, RoleName = role.Name }; if (_store.Save(relation)) { _usersInRole.Remove(role.Name); _rolesForUser.Remove(user.Login); } else { throw new Exception("Não foi possivel adicionar o usuário ao papel."); } } }); }
/// <summary> /// 添加用户 /// </summary> /// <param name="u"></param> /// <returns></returns> public int UserInsert(string AccountName, string Pwd, string Sex, string Phone, DateTime CreTime, string OwnRole) { Users u = new Users(); u.AccountName = AccountName; u.Pwd = Pwd; u.Sex = Sex; u.Phone = Phone; u.CreTime = CreTime; int i = user.UserAdd(u); var a = OwnRole.Split(','); int userid = user.GetUserId(); for (int j = 0; j < a.Length; j++) { UserRoleRelation relation = new UserRoleRelation(); relation.UserId = userid; relation.RoleId = int.Parse(a[j]); int result = user.RARolesAdd(relation); } Users us = (Users)Session["User"]; if (i > 0) { logs.Add(us.ID, "添加用户", 1); } else { logs.Add(us.ID, "添加用户", 0); } return(i); }
public override async Task <int> InsertAsync(ApplicationEntity obj) { using (var transaction = new TransactionScope(TransactionScopeOption.Required, TransactionScopeAsyncFlowOption.Enabled)) { await base.InsertAsync(obj); var sql = obj.Account.ToSQLinqInsert(dialect: base.SqlDialect).ToSQL(); await this.Connection.ExecuteAsync(sql.ToQuery(), sql.Parameters); var role = obj.UserRole.First(); var rel = new UserRoleRelation() { Id = this._idGenerator.NewId(), RoleId = role.Id, UserId = obj.Account.Id }; var relInsert = rel.ToSQLinqInsert(dialect: base.SqlDialect); var relSql = relInsert.ToSQL(); var count = await this.Connection.ExecuteAsync(relSql.ToQuery(), relSql.Parameters); obj.CallbackConfigs.ForEach(async x => { sql = x.ToSQLinqInsert(dialect: base.SqlDialect).ToSQL(); count += await this.Connection.ExecuteAsync(sql.ToQuery(), sql.Parameters); }); transaction.Complete(); return(count); } }
public async Task <UserRoleRelation> QueryByRole(Guid roleId, Guid id) { UserRoleRelation relation = null; await DBTransactionHelper.SqlTransactionWorkAsync(DBTypes.SqlServer, true, false, _privilegeManagementConnectionFactory.CreateReadForPrivilegeManagement(), async (conn, transaction) => { SqlTransaction sqlTran = null; if (transaction != null) { sqlTran = (SqlTransaction)transaction; } using (SqlCommand commond = new SqlCommand() { Connection = (SqlConnection)conn, CommandType = CommandType.Text, Transaction = sqlTran, CommandText = string.Format(@"select {0},{1},{2} from [UserRoleRelation] as urr join [role] as r on urr.[roleid]=r.[id] join [PrivilegeSystem] as s on urr.[systemid]=s.[id] where urr.[id]=@id and urr.[roleid]", StoreHelper.GetUserRoleRelationSelectFields("urr"), StoreHelper.GetRoleSelectFields("r"), StoreHelper.GetPrivilegeSystemSelectFields("s")) }) { var parameter = new SqlParameter("@id", SqlDbType.UniqueIdentifier) { Value = id }; commond.Parameters.Add(parameter); parameter = new SqlParameter("@roleid", SqlDbType.UniqueIdentifier) { Value = roleId }; commond.Parameters.Add(parameter); commond.Prepare(); SqlDataReader reader = null; using (reader = await commond.ExecuteReaderAsync()) { if (await reader.ReadAsync()) { relation = new UserRoleRelation(); StoreHelper.SetUserRoleRelationSelectFields(relation, reader, "urr"); relation.Role = new Role(); StoreHelper.SetRoleSelectFields(relation.Role, reader, "r"); relation.System = new PrivilegeSystem(); StoreHelper.SetPrivilegeSystemSelectFields(relation.System, reader, "s"); } reader.Close(); } } }); return(relation); }
public async Task Update(UserRoleRelation relation) { await DBTransactionHelper.SqlTransactionWorkAsync(DBTypes.SqlServer, false, false, _privilegeManagementConnectionFactory.CreateAllForPrivilegeManagement(), async (conn, transaction) => { SqlTransaction sqlTran = null; if (transaction != null) { sqlTran = (SqlTransaction)transaction; } using (SqlCommand commond = new SqlCommand() { Connection = (SqlConnection)conn, CommandType = CommandType.Text, Transaction = sqlTran, CommandText = @"update [UserRoleRelation] set [userkey]=@userkey,[systemid]=@systemid,[roleid]=@roleid,[modifytime]=getutcdate() where [id]=@id" }) { var parameter = new SqlParameter("@id", SqlDbType.UniqueIdentifier) { Value = relation.ID }; commond.Parameters.Add(parameter); parameter = new SqlParameter("@userkey", SqlDbType.NVarChar, 150) { Value = relation.UserKey }; commond.Parameters.Add(parameter); parameter = new SqlParameter("@systemid", SqlDbType.UniqueIdentifier) { Value = relation.System.ID }; commond.Parameters.Add(parameter); parameter = new SqlParameter("@roleid", SqlDbType.UniqueIdentifier) { Value = relation.Role.ID }; commond.Parameters.Add(parameter); commond.Prepare(); await commond.ExecuteNonQueryAsync(); } }); }
/// <summary> /// Updates the specified user aggregate. /// </summary> /// <param name="aggregate">The user aggregate.</param> /// <exception cref="System.ArgumentNullException">When user aggregate is null.</exception> public void Update(DB.Models.User.User aggregate) { if (aggregate == null) { throw new ArgumentNullException("aggregate"); } var user = _context.Users.Find(aggregate.Id); user.FirstName = aggregate.FirstName; user.LastName = aggregate.LastName; user.DateOfBirth = aggregate.DateOfBirth; user.Image = aggregate.Image; user.Phone = aggregate.Phone; user.IsDeleted = aggregate.IsDeleted; foreach (var role in aggregate.Roles) { var newRole = new UserRoleRelation { RoleId = role, UserId = aggregate.Id }; var oldRole = _context.UserRoleRelations.FirstOrDefault(x => x.UserId == aggregate.Id); if (oldRole == null) { _context.UserRoleRelations.Add(newRole); continue; } if (oldRole.UserId == newRole.UserId && oldRole.RoleId == newRole.RoleId) { continue; } _context.UserRoleRelations.Remove(oldRole); _context.UserRoleRelations.AddOrUpdate(newRole); } if (aggregate.Mood != null) { _context.Moods.AddOrUpdate(new UserMood { Date = aggregate.Mood.Date, Rate = aggregate.Mood.Rate, UserId = aggregate.Id }); } _context.SaveChanges(); }
public async Task RoleAddOneUser(long roleId, long userId) { var rel = await this._userRoleRel.QueryFirstAsync(x => x.RoleId == roleId && x.UserId == userId); if (rel != null) { return; } rel = new UserRoleRelation { Id = this._idGenerator.NewId(), UserId = userId, RoleId = roleId }; await this._userRoleRel.InsertAsync(rel); }
/// <summary> /// 为权限系统从DbDataReader中赋值 /// </summary> /// <param name="queue"></param> /// <param name="reader"></param> /// <param name="prefix"></param> public static void SetUserRoleRelationSelectFields(UserRoleRelation relation, DbDataReader reader, string prefix) { relation.ID = (Guid)reader[string.Format("{0}id", prefix)]; if (reader[string.Format("{0}userkey", prefix)] != DBNull.Value) { relation.UserKey = reader[string.Format("{0}userkey", prefix)].ToString(); } if (reader[string.Format("{0}createtime", prefix)] != DBNull.Value) { relation.CreateTime = (DateTime)reader[string.Format("{0}createtime", prefix)]; } if (reader[string.Format("{0}modifytime", prefix)] != DBNull.Value) { relation.ModifyTime = (DateTime)reader[string.Format("{0}modifytime", prefix)]; } }
public UserRoleRelation ToUserRoleRelation(string jsonData) { JsonResponseReader reader = new JsonResponseReader(jsonData); string userId = reader.GetString("userId"); string roleId = reader.GetString("roleId"); if (userId == null) { throw new NoNullAllowedException("未能正常解析用户ID"); } if (roleId == null) { throw new NoNullAllowedException("未能正常解析等级ID"); } var user = new UserRoleRelation(userId, roleId); return(user); }
public void AddRelationRole(Guid relationId, long userId, long relationUserId) { var relationRoles = _userRoleRelationRepository.GetAll().Where(x => x.RelationId == relationId).ToList(); foreach (var item in relationRoles) { _userRoleRelationRepository.Delete(item); } var roles = _userRoleRepository.GetAll().Where(x => x.UserId == userId).ToList(); foreach (var item in roles) { var info = new UserRoleRelation() { RoleId = item.RoleId, UserId = relationUserId, RelationId = relationId }; _userRoleRelationRepository.Insert(info); } }
public async Task QueryByRole(Guid roleId, Func <UserRoleRelation, Task> callback) { List <UserRoleRelation> relationList = new List <UserRoleRelation>(); await DBTransactionHelper.SqlTransactionWorkAsync(DBTypes.SqlServer, true, false, _privilegeManagementConnectionFactory.CreateReadForPrivilegeManagement(), async (conn, transaction) => { Int64?sequence = null; int pageSize = 500; while (true) { relationList.Clear(); SqlTransaction sqlTran = null; if (transaction != null) { sqlTran = (SqlTransaction)transaction; } using (SqlCommand commond = new SqlCommand() { Connection = (SqlConnection)conn, CommandType = CommandType.Text, Transaction = sqlTran }) { if (!sequence.HasValue) { commond.CommandText = string.Format(@"select top (@pagesize) {0} from [UserRoleRelation] as urr join [Role] as r on urr.[roleid]=r.[id] join [PrivilegeSystem] as s on urr.[systemid]=s.[id] where r.[id]=@roleid order by urr.[sequence]", StoreHelper.GetUserRoleRelationSelectFields("urr"), StoreHelper.GetRoleSelectFields("r"), StoreHelper.GetPrivilegeSystemSelectFields("s")); } else { commond.CommandText = string.Format(@"select top (@pagesize) {0} from [UserRoleRelation] as urr join [Role] as r on urr.[roleid]=r.[id] join [PrivilegeSystem] as s on urr.[systemid]=s.[id] where r.[id]=@roleid and urr.[sequence]>@sequence order by urr.[sequence]", StoreHelper.GetUserRoleRelationSelectFields("urr"), StoreHelper.GetRoleSelectFields("r"), StoreHelper.GetPrivilegeSystemSelectFields("s")); } var parameter = new SqlParameter("@roleid", SqlDbType.UniqueIdentifier) { Value = roleId }; commond.Parameters.Add(parameter); parameter = new SqlParameter("@pagesize", SqlDbType.Int) { Value = pageSize }; commond.Parameters.Add(parameter); if (sequence.HasValue) { parameter = new SqlParameter("@sequence", SqlDbType.BigInt) { Value = sequence }; commond.Parameters.Add(parameter); } commond.Prepare(); SqlDataReader reader = null; using (reader = await commond.ExecuteReaderAsync()) { while (await reader.ReadAsync()) { var relation = new UserRoleRelation(); StoreHelper.SetUserRoleRelationSelectFields(relation, reader, "urr"); sequence = (Int64)reader["urrsequence"]; relation.Role = new Role(); StoreHelper.SetRoleSelectFields(relation.Role, reader, "r"); relation.System = new PrivilegeSystem(); StoreHelper.SetPrivilegeSystemSelectFields(relation.System, reader, "s"); relationList.Add(relation); } reader.Close(); } } foreach (var relationItem in relationList) { await callback(relationItem); } if (relationList.Count != pageSize) { break; } } }); }
public async Task Add(UserRoleRelation relation) { await DBTransactionHelper.SqlTransactionWorkAsync(DBTypes.SqlServer, false, false, _privilegeManagementConnectionFactory.CreateAllForPrivilegeManagement(), async (conn, transaction) => { SqlTransaction sqlTran = null; if (transaction != null) { sqlTran = (SqlTransaction)transaction; } using (SqlCommand commond = new SqlCommand() { Connection = (SqlConnection)conn, CommandType = CommandType.Text, Transaction = sqlTran }) { if (relation.ID == Guid.Empty) { commond.CommandText = @"insert into [UserRoleRelation]([id],[userkey],[systemid],[roleid],[createtime],[modifytime]) values(default,@userkey,@systemid,getutcdate(),getutcdate()); select @newid=[id] from [UserRoleRelation] where [sequence]=SCOPE_IDENTITY()"; } else { commond.CommandText = @"insert into [UserRoleRelation]([id],[userkey],[systemid],[roleid],[createtime],[modifytime]) values(@id,@userkey,@systemid,@roleid,getutcdate(),getutcdate())"; } SqlParameter parameter; if (relation.ID != Guid.Empty) { parameter = new SqlParameter("@id", SqlDbType.UniqueIdentifier) { Value = relation.ID }; commond.Parameters.Add(parameter); } else { parameter = new SqlParameter("@newid", SqlDbType.UniqueIdentifier) { Direction = ParameterDirection.Output }; commond.Parameters.Add(parameter); } parameter = new SqlParameter("@userkey", SqlDbType.NVarChar, 150) { Value = relation.UserKey }; commond.Parameters.Add(parameter); parameter = new SqlParameter("@systemid", SqlDbType.UniqueIdentifier) { Value = relation.System.ID }; commond.Parameters.Add(parameter); parameter = new SqlParameter("@roleid", SqlDbType.UniqueIdentifier) { Value = relation.Role.ID }; commond.Parameters.Add(parameter); commond.Prepare(); await commond.ExecuteNonQueryAsync(); if (relation.ID == Guid.Empty) { relation.ID = (Guid)commond.Parameters["@newid"].Value; } } }); }
/// <summary> /// 用户与角色关系添加 /// </summary> /// <param name="rolePermissionRelation"></param> /// <returns></returns> public int RARolesAdd(UserRoleRelation userRoleRelation) { int result = DapperHelper.Insert <UserRoleRelation>(userRoleRelation); return(result); }
public static void Initialize(SchedulerZContext context) { context.Database.EnsureCreated(); if (context.Users.Any()) { return; } var user = new User() { Username = "******", Password = "******", Name = "Admin", Avatar = "https://gw.alipayobjects.com/zos/rmsportal/jZUIxmJycoymBprLOUbT.png", LastLoginIp = "192.168.1.180", LastLoginTime = DateTime.Now, Status = 1, CreateTime = DateTime.Now, IsDelete = false }; context.Users.Add(user); context.SaveChanges(); var role = new Role() { Identify = "admin", Name = "管理员", CreateTime = DateTime.Now, }; context.Roles.Add(role); context.SaveChanges(); var routers = new Router[] { new Router() { Title = "仪表盘", Path = "/dashboard", Name = "Dashboard", Component = "RouteView", Permission = "dashboard", Icon = "dashboard", Show = true, Redirect = "/dashboard/workplace", ParentId = 0, Sort = 1000, CreateTime = DateTime.Now }, new Router() { Title = "工作台", Path = "/dashboard/workplace", Name = "Workplace", Component = "Workplace", Permission = "dashboard", Icon = "", Show = true, Redirect = "", ParentId = 1, Sort = 1001, CreateTime = DateTime.Now }, new Router() { Title = "系统管理", Path = "/system", Name = "System", Component = "RouteView", Permission = "system", Icon = "slack", Show = true, Redirect = "/system/user", ParentId = 0, Sort = 2000, CreateTime = DateTime.Now }, new Router() { Title = "用户管理", Path = "/system/user", Name = "User", Component = "User", Permission = "system", Icon = "", Show = true, Redirect = "", ParentId = 3, Sort = 2001, CreateTime = DateTime.Now }, new Router() { Title = "角色管理", Path = "/system/role", Name = "Role", Component = "Role", Permission = "system", Icon = "", Show = true, Redirect = "", ParentId = 3, Sort = 2002, CreateTime = DateTime.Now }, new Router() { Title = "权限管理", Path = "/system/permission", Name = "Permission", Component = "Permission", Permission = "system", Icon = "", Show = true, Redirect = "", ParentId = 3, Sort = 2003, CreateTime = DateTime.Now }, new Router() { Title = "节点管理", Path = "/node", Name = "Node", Component = "RouteView", Permission = "", Icon = "global", Show = true, Redirect = "", ParentId = 0, Sort = 3000, CreateTime = DateTime.Now }, new Router() { Title = "节点列表", Path = "/node/list", Name = "NodeList", Component = "NodeList", Permission = "", Icon = "", Show = true, Redirect = "", ParentId = 7, Sort = 3001, CreateTime = DateTime.Now }, new Router() { Title = "服务列表", Path = "/node/services", Name = "Services", Component = "Services", Permission = "", Icon = "", Show = true, Redirect = "", ParentId = 7, Sort = 3002, CreateTime = DateTime.Now }, new Router() { Title = "任务列表", Path = "/jobs", Name = "Jobs", Component = "Jobs", Permission = "", Icon = "schedule", Show = true, Redirect = "", ParentId = 0, Sort = 4000, CreateTime = DateTime.Now }, new Router() { Title = "系统日志", Path = "/logs", Name = "Logs", Component = "Logs", Permission = "", Icon = "file-search", Show = true, Redirect = "", ParentId = 0, Sort = 5000, CreateTime = DateTime.Now } }; context.Routers.AddRange(routers); context.SaveChanges(); var userRoleRelation = new UserRoleRelation() { UserId = user.Id, RoleId = role.Id }; context.UserRoleRelations.Add(userRoleRelation); var roleRouterRelations = new List <RoleRouterRelation>(); foreach (var item in routers) { roleRouterRelations.Add(new RoleRouterRelation() { RoleId = role.Id, RouterId = item.Id }); } context.RoleRouterRelations.AddRange(roleRouterRelations); context.SaveChanges(); }
public async Task <QueryResult <UserRoleRelation> > QueryByRoleAndUserKey(Guid roleId, string userKey, int page, int pageSize) { QueryResult <UserRoleRelation> result = new QueryResult <UserRoleRelation>(); await DBTransactionHelper.SqlTransactionWorkAsync(DBTypes.SqlServer, true, false, _privilegeManagementConnectionFactory.CreateReadForPrivilegeManagement(), async (conn, transaction) => { SqlTransaction sqlTran = null; if (transaction != null) { sqlTran = (SqlTransaction)transaction; } using (SqlCommand commond = new SqlCommand() { Connection = (SqlConnection)conn, CommandType = CommandType.Text, Transaction = sqlTran, CommandText = string.Format(@"set @currentpage=@page select @count= count(*) from [UserRoleRelation] as urr join [Role] as r on urr.[roleid]=r.[id] join [PrivilegeSystem] as s on urr.[systemid]=s.[id] where r.[id]=@roleid and urr.[userkey] like @userkey if @pagesize*@page>=@count begin set @currentpage= @count/@pagesize if @count%@pagesize<>0 begin set @currentpage=@currentpage+1 end if @currentpage=0 set @currentpage=1 end else if @page<1 begin set @currentpage=1 end select {0},{1},{2} from [UserRoleRelation] as urr join [Role] as r on urr.[roleid]=r.[id] join [PrivilegeSystem] as s on urr.[systemid]=s.[id] where r.[id]=@roleid and urr.[userkey] like @userkey order by urr.[sequence] desc offset (@pagesize * (@currentpage - 1)) rows fetch next @pagesize rows only;" , StoreHelper.GetUserRoleRelationSelectFields("urr"), StoreHelper.GetRoleSelectFields("r"), StoreHelper.GetPrivilegeSystemSelectFields("s")) }) { var parameter = new SqlParameter("@page", SqlDbType.Int) { Value = page }; commond.Parameters.Add(parameter); parameter = new SqlParameter("@pagesize", SqlDbType.Int) { Value = pageSize }; parameter = new SqlParameter("@roleid", SqlDbType.UniqueIdentifier) { Value = roleId }; commond.Parameters.Add(parameter); parameter = new SqlParameter("@userKey", SqlDbType.NVarChar, 150) { Value = $"{userKey.ToSqlLike()}%" }; commond.Parameters.Add(parameter); parameter = new SqlParameter("@count", SqlDbType.Int) { Direction = ParameterDirection.Output }; commond.Parameters.Add(parameter); parameter = new SqlParameter("@currentpage", SqlDbType.Int) { Direction = ParameterDirection.Output }; commond.Parameters.Add(parameter); commond.Prepare(); SqlDataReader reader = null; using (reader = await commond.ExecuteReaderAsync()) { while (await reader.ReadAsync()) { var relation = new UserRoleRelation(); StoreHelper.SetUserRoleRelationSelectFields(relation, reader, "urr"); relation.Role = new Role(); StoreHelper.SetRoleSelectFields(relation.Role, reader, "r"); relation.System = new PrivilegeSystem(); StoreHelper.SetPrivilegeSystemSelectFields(relation.System, reader, "s"); result.Results.Add(relation); } reader.Close(); result.TotalCount = (int)commond.Parameters["@count"].Value; result.CurrentPage = (int)commond.Parameters["@currentpage"].Value; } } }); return(result); }
/// <summary> /// 删除用户角色关联对象 /// </summary> /// <param name="relation"></param> private void Remove(UserRoleRelation relation) { UnitOfWork.RegisterRemove<UserRoleRelation, int>(relation); }
/// <summary> /// <see cref="IUserRoleRelationService"/> /// </summary> /// <param name="user"><see cref="IUserRoleRelationService"/></param> /// <param name="role"><see cref="IUserRoleRelationService"/></param> public void AddRelation(User user, Role role) { Guidance.ArgumentNotNull(user, "user"); Guidance.ArgumentNotNull(role, "role"); var relation = new UserRoleRelation(user, role); UnitOfWork.RegisterNew<UserRoleRelation, int>(relation); }
public JsonResult Register(UserRegisterViewModel model) { bool success = false; string message = ""; var emailControl = RegexExtension.EmailRegexControl(model.Email); var passwordControl = PasswordControlExtension.PasswordControl(model.Password, model.RePassword); var hasEmail = db.Users.FirstOrDefault(x => x.Email == model.Email); if (hasEmail != null || !passwordControl || !passwordControl || string.IsNullOrEmpty(model.Email) || string.IsNullOrEmpty(model.Password) || string.IsNullOrEmpty(model.RePassword) || string.IsNullOrEmpty(model.Name) || string.IsNullOrEmpty(model.Surname) || string.IsNullOrEmpty(model.PhoneNumber)) { if (hasEmail != null) { success = false; message = "Email adresi sistemimizde kayıtlıdır."; } if (!emailControl) { success = emailControl; message = "Emailinizi kontrol ediniz"; } if (!passwordControl) { success = passwordControl; message = "Şifreler eşleşmiyor"; } if (string.IsNullOrEmpty(model.Email) || string.IsNullOrEmpty(model.Password) || string.IsNullOrEmpty(model.RePassword) || string.IsNullOrEmpty(model.Name) || string.IsNullOrEmpty(model.Surname) || string.IsNullOrEmpty(model.PhoneNumber)) { message = "Boş alanları doldurunuz!"; } } else { var userRegisterModel = new Users { Email = model.Email, Password = model.Password, CreatedDate = DateTime.Now, Name = model.Name, Surname = model.Surname, TelNo = model.PhoneNumber }; var user = db.Users.Add(userRegisterModel); var userRoleRelationModel = new UserRoleRelation() { FkUserId = user.Id, FkUserRoleId = 2, Status = 1, CreatedDate = DateTime.Now, }; db.UserRoleRelation.Add(userRoleRelationModel); db.SaveChanges(); success = true; message = $"{user.Name } {user.Surname} Kayıt işlemi başarıyla gerçekleşti."; } var result = new ResultViewModel() { Message = message, Success = success }; return(Json(result)); }
/// <summary> /// 重载seed方法放入初始化数据 /// </summary> /// <param name="context"></param> protected override void Seed(Bootstrap.Entity.Repository.EntityDBContext context) { // This method will be called after migrating to the latest version. // You can use the DbSet<T>.AddOrUpdate() helper extension method // to avoid creating duplicate seed data. if (context.UserSet.FirstOrDefault() == null) { //默认用户 var defaultUser = new User { Sex = User.Gender.男, NickName = "赵日天", UserName = "******", PassWord = "******" }; context.UserSet.Add(defaultUser); } if (context.NavigationMenuSet.FirstOrDefault() == null) { //默认菜单 var defaultMenuList = new List <NavigationMenu>() { new NavigationMenu { MenuName = "控制台", ShortName = "system_console", Url = "/Manage/Home/Index" }, new NavigationMenu { MenuName = "系统设置", ShortName = "system_set" }, new NavigationMenu { MenuName = "菜单管理", ShortName = "system_set_menu", Url = "/Manage/Menu/Index", ParentMenuId = 2 }, new NavigationMenu { MenuName = "角色管理", ShortName = "system_set_role", Url = "/Manage/Role/Index", ParentMenuId = 2 }, new NavigationMenu { MenuName = "用户管理", ShortName = "system_set_user", Url = "/Manage/User/Index", ParentMenuId = 2 } }; defaultMenuList.ForEach(s => context.NavigationMenuSet.Add(s)); } if (context.RoleSet.FirstOrDefault() == null) { //默认角色 var defaultRoleList = new List <Role>() { new Role { RoleName = "管理员", RoleDesc = "管理员角色" }, new Role { RoleName = "用户", RoleDesc = "用户角色" }, }; defaultRoleList.ForEach(s => context.RoleSet.Add(s)); } if (context.UserRoleRelationSet.FirstOrDefault() == null) { //默认用户-角色 var defaultUserRole = new UserRoleRelation { RoleId = 1, UserId = 1, }; context.UserRoleRelationSet.Add(defaultUserRole); } if (context.RolePermissionRelationSet.FirstOrDefault() == null) { //默认角色-权限 var defaultRolePermissionList = new List <RolePermissionRelation> { new RolePermissionRelation { RoleId = 1, PermissionName = "/Manage/Home" }, new RolePermissionRelation { RoleId = 1, PermissionName = "/Manage/Home/Index" }, new RolePermissionRelation { RoleId = 1, PermissionName = "/Manage/Menu" }, new RolePermissionRelation { RoleId = 1, PermissionName = "/Manage/Menu/Index" }, new RolePermissionRelation { RoleId = 1, PermissionName = "/Manage/Menu/AddOrEidtMenuView" }, new RolePermissionRelation { RoleId = 1, PermissionName = "/Manage/Menu/GetMenuTree" }, new RolePermissionRelation { RoleId = 1, PermissionName = "/Manage/Menu/AddOrEidtMenu" }, new RolePermissionRelation { RoleId = 1, PermissionName = "/Manage/Menu/DeleteMenu" }, new RolePermissionRelation { RoleId = 1, PermissionName = "/Manage/Role" }, new RolePermissionRelation { RoleId = 1, PermissionName = "/Manage/Role/Index" }, new RolePermissionRelation { RoleId = 1, PermissionName = "/Manage/Role/AddOrEidtRoleView" }, new RolePermissionRelation { RoleId = 1, PermissionName = "/Manage/Role/ChangePermissionView" }, new RolePermissionRelation { RoleId = 1, PermissionName = "/Manage/Role/AddOrEditRole" }, new RolePermissionRelation { RoleId = 1, PermissionName = "/Manage/Role/BatchDeleteRole" }, new RolePermissionRelation { RoleId = 1, PermissionName = "/Manage/Role/GetRoleList" }, new RolePermissionRelation { RoleId = 1, PermissionName = "/Manage/Role/DeleteRole" }, new RolePermissionRelation { RoleId = 1, PermissionName = "/Manage/Role/GetRolePermissionList" }, new RolePermissionRelation { RoleId = 1, PermissionName = "/Manage/Role/SaveRolePermission" }, new RolePermissionRelation { RoleId = 1, PermissionName = "/Manage/User" }, new RolePermissionRelation { RoleId = 1, PermissionName = "/Manage/User/Index" }, new RolePermissionRelation { RoleId = 1, PermissionName = "/Manage/User/ChangePermissionView" }, new RolePermissionRelation { RoleId = 1, PermissionName = "/Manage/User/AddOrEditUserView" }, new RolePermissionRelation { RoleId = 1, PermissionName = "/Manage/User/GetUserList" }, new RolePermissionRelation { RoleId = 1, PermissionName = "/Manage/User/SaveUserPermission" }, new RolePermissionRelation { RoleId = 1, PermissionName = "/Manage/User/SaveUserInfo" }, }; defaultRolePermissionList.ForEach(s => context.RolePermissionRelationSet.Add(s)); } if (context.UserPermissionRelationSet.FirstOrDefault() == null) { //默认用户-权限 var defaultUserPermissionList = new List <UserPermissionRelation> { new UserPermissionRelation { UserId = 1, PermissionName = "/Manage/Home" }, new UserPermissionRelation { UserId = 1, PermissionName = "/Manage/Home/Index" }, new UserPermissionRelation { UserId = 1, PermissionName = "/Manage/Menu" }, new UserPermissionRelation { UserId = 1, PermissionName = "/Manage/Menu/Index" }, new UserPermissionRelation { UserId = 1, PermissionName = "/Manage/Menu/AddOrEidtMenuView" }, new UserPermissionRelation { UserId = 1, PermissionName = "/Manage/Menu/GetMenuTree" }, new UserPermissionRelation { UserId = 1, PermissionName = "/Manage/Menu/AddOrEidtMenu" }, new UserPermissionRelation { UserId = 1, PermissionName = "/Manage/Menu/DeleteMenu" }, new UserPermissionRelation { UserId = 1, PermissionName = "/Manage/Role" }, new UserPermissionRelation { UserId = 1, PermissionName = "/Manage/Role/Index" }, new UserPermissionRelation { UserId = 1, PermissionName = "/Manage/Role/AddOrEidtRoleView" }, new UserPermissionRelation { UserId = 1, PermissionName = "/Manage/Role/ChangePermissionView" }, new UserPermissionRelation { UserId = 1, PermissionName = "/Manage/Role/AddOrEditRole" }, new UserPermissionRelation { UserId = 1, PermissionName = "/Manage/Role/BatchDeleteRole" }, new UserPermissionRelation { UserId = 1, PermissionName = "/Manage/Role/GetRoleList" }, new UserPermissionRelation { UserId = 1, PermissionName = "/Manage/Role/DeleteRole" }, new UserPermissionRelation { UserId = 1, PermissionName = "/Manage/Role/GetRolePermissionList" }, new UserPermissionRelation { UserId = 1, PermissionName = "/Manage/Role/SaveRolePermission" }, new UserPermissionRelation { UserId = 1, PermissionName = "/Manage/User" }, new UserPermissionRelation { UserId = 1, PermissionName = "/Manage/User/Index" }, new UserPermissionRelation { UserId = 1, PermissionName = "/Manage/User/ChangePermissionView" }, new UserPermissionRelation { UserId = 1, PermissionName = "/Manage/User/AddOrEditUserView" }, new UserPermissionRelation { UserId = 1, PermissionName = "/Manage/User/GetUserList" }, new UserPermissionRelation { UserId = 1, PermissionName = "/Manage/User/SaveUserPermission" }, new UserPermissionRelation { UserId = 1, PermissionName = "/Manage/User/SaveUserInfo" }, }; defaultUserPermissionList.ForEach(s => context.UserPermissionRelationSet.Add(s)); } context.SaveChanges(); }