123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134 |
- using Bowin.Common.Linq;
- using Bowin.Common.Linq.Entity;
- using YLShipBuildLandMap.Entity;
- using YLShipBuildLandMap.Entity.ViewModel.SystemSetting;
- using Microsoft.EntityFrameworkCore;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Linq.Expressions;
- using System.Text;
- using System.Threading.Tasks;
- namespace YLShipBuildLandMap.Services.SystemSetting
- {
- public class RoleService : IRoleService
- {
- private YLShipBuildLandMapContext DbContext { get; set; }
- public RoleService(YLShipBuildLandMapContext dbContext)
- {
- DbContext = dbContext;
- }
- private IQueryable<RoleView> GetRoleViewQueryable(Expression<Func<SysRole, bool>> exp)
- {
- var sql = (from r in this.DbContext.SysRole.Where(exp)
- select new RoleView
- {
- RoleID = r.RoleId,
- RoleName = r.RoleName,
- Description = r.Description,
- IsSystemRole = r.IsSystemRole,
- CreateTime = r.CreateTime
- });
- return sql;
- }
- public IGridResultSet<RoleView> GetRoleViewsForSelect(string roleName, int? pageIndex = null, int? pageSize = null)
- {
- Expression<Func<SysRole, bool>> exp = (x => x.RecordStatus > 0);
- if (!string.IsNullOrEmpty(roleName))
- {
- exp = exp.And(x => x.RoleName.Contains(roleName));
- }
- var sql = GetRoleViewQueryable(exp).OrderBy(x => x.RoleName);
- return sql.ToGridResultSet(pageIndex, pageSize);
- }
- public IGridResultSet<RoleView> GetRoleViewList(string roleName, int? pageIndex = null, int? pageSize = null)
- {
- Expression<Func<SysRole, bool>> exp = (x => x.RecordStatus > 0);
- if (!string.IsNullOrEmpty(roleName))
- {
- exp = exp.And(x => x.RoleName.Contains(roleName));
- }
- var query = GetRoleViewQueryable(exp);
- return query.OrderBy(x => x.RoleName)
- .ToGridResultSet<RoleView>(pageIndex, pageSize);
- }
- public async Task Save(RoleView roleView, List<string> functionCodes, Guid operatorID)
- {
- DateTime nowTime = DateTime.Now;
- SysRole role = new SysRole();
- if (roleView.RoleID.HasValue)
- {
- //先删除角色所有权限,后面再添加
- var delCodes = this.DbContext.SysRoleSysFunctionCode.Where(x => x.RoleId == roleView.RoleID).ToArrayAsync();
- this.DbContext.SysRoleSysFunctionCode.RemoveRange(delCodes.Result);
- role = DbContext.SysRole
- .FirstOrDefault(x => x.RoleId == roleView.RoleID);
- }
- else
- {
- role.RoleId = Guid.NewGuid();
- role.RoleName = roleView.RoleName;
- role.Description = roleView.Description;
- role.IsSystemRole = false;
- role.RecordStatus = 1;
- role.CreateUserId = operatorID;
- role.CreateTime = nowTime;
- this.DbContext.Add(role);
- }
- role.RoleName = roleView.RoleName;
- role.Description = roleView.Description;
- role.IsSystemRole = roleView.IsSystemRole;
- role.ModifyUserId = operatorID;
- role.ModifyTime = nowTime;
- foreach(string code in functionCodes)
- {
- SysRoleSysFunctionCode rf = new SysRoleSysFunctionCode();
- rf.RoleId = role.RoleId;
- rf.FunctionCode = code;
- this.DbContext.Add(rf);
- }
- await this.DbContext.SaveChangesAsync();
- }
- public RoleView GetRoleView(Guid roleID)
- {
- return this.GetRoleViewQueryable(x => x.RoleId == roleID).FirstOrDefault();
- }
- public async Task Delete(List<Guid> roleIDList)
- {
- var delRoles = this.DbContext.SysRole.Where(x => roleIDList.Contains(x.RoleId)).ToArrayAsync();
- this.DbContext.SysRole.RemoveRange(delRoles.Result);
- await this.DbContext.SaveChangesAsync();
- }
- public RoleView GetRoleViewByName(string roleName)
- {
- return this.GetRoleViewQueryable(x => x.RoleName == roleName).FirstOrDefault();
- }
- public List<string> GetRoleMenuList(Guid roleID)
- {
- throw new NotImplementedException();
- }
- }
- }
|