/// <summary> /// 修改密码 /// </summary> /// <param name="modifyPwdParam"></param> /// <param name="currentUser"></param> /// <returns></returns> public async Task <ResponseModel <string> > ModifyPwdAsync(ModifyPwdParam modifyPwdParam, UserCacheBo currentUser) { var result = new ResponseModel <string>(); if (modifyPwdParam.NewPassWord == modifyPwdParam.OldPassWord) { return(result.Fail(ResponseCode.Fail, "不允许原密码和新密码相同的修改")); } if (modifyPwdParam.OldPassWord.Md5Encrypt() == currentUser.PassWord) { var updateResult = await SysUserDao.ModifyPwdAsync(modifyPwdParam, currentUser.UserId); if (updateResult) { // 修改成功 登出 重新登录 await LogoutAsync(currentUser); return(result.Succeed("修改成功,请重新登录")); } return(result.Fail(ResponseCode.Fail, "修改失败,请稍后再试")); } return(result.Fail(ResponseCode.Fail, "原密码不正确")); }
public virtual async Task <ResponseModel <bool> > RegisterUserAsync(RegisterUserParam registerUserParam) { var result = new ResponseModel <bool>(); var verificationResult = await VerificationCaptchaAsync(CacheKeys.REGISTERCAPTCHA, registerUserParam.Email, registerUserParam.Captcha, false); if (verificationResult != "验证通过") { result.Fail(ResponseCode.Fail, verificationResult, false); return(result); } if (await ExistUserAsync(registerUserParam.Email)) { result.Fail(ResponseCode.Fail, "该邮箱已存在,请切换或找回密码", false); return(result); } var count = await SaveRegisterUserAsync(registerUserParam); if (count > 0) { return(result.Succeed(true)); } return(result.Fail(ResponseCode.Fail, "保存失败,请稍后再试", false)); }
public virtual async Task <BaseResponseModel> RemoveManagerUserAsync(long uid, UserCacheBo currentUser) { var result = new ResponseModel <bool>(); var db = SysUserDao.CurrentDbContext; var deleteUser = await db.SysUsers.FirstOrDefaultAsync(c => c.UserId == uid && c.TenantId == currentUser.UserId && c.State == 1); if (deleteUser == null) { return(result.Fail("账号不存在")); } // 管理员创建者都是0 注册的 if (deleteUser.CreatedBy <= 0) { return(result.Fail("管理员只读")); } var count = 0; count += await db.SysUsers.Where(c => c.UserId == uid && c.TenantId == currentUser.TenantId).DeleteFromQueryAsync(); count += await db.SysUserRoleRelations.Where(c => c.UserId == uid && c.TenantId == currentUser.TenantId).DeleteFromQueryAsync(); count += await db.SaveChangesAsync(); return(count > 0 ? result.Succeed(true) : result.Fail("删除失败")); }
/// <summary> /// 新增角色 /// </summary> /// <param name="incrementRoleParam"></param> /// <param name="currentUser"></param> /// <returns></returns> public async Task <BaseResponseModel> AddRoleAsync(IncrementRoleParam incrementRoleParam, UserCacheBo currentUser) { var result = new ResponseModel <string>(); var db = SysRoleDao.CurrentDbContext; SysRoleDao.CloseTracking(); if (await db.SysRoles.CountAsync(c => c.TenantId == currentUser.TenantId && !c.Deleted) > 500) { return(result.Fail("一个租户下角色上限为500个")); } if (await db.SysRoles.AnyAsync(c => c.TenantId == currentUser.TenantId && !c.Deleted && c.RoleName == incrementRoleParam.RoleName)) { return(result.Fail("角色名已存在")); } var role = new SysRole() { TenantId = currentUser.TenantId, CreatedBy = currentUser.UserId, CreatedTime = DateTime.Now, Deleted = false, RoleDesc = incrementRoleParam.RoleDesc ?? "", RoleName = incrementRoleParam.RoleName, }; await db.SysRoles.AddAsync(role); var count = await db.SaveChangesAsync(); return(count > 0 ? result.Succeed("添加成功") : result.Fail("添加失败")); }
/// <summary> /// 修改角色 /// </summary> /// <param name="incrementRoleParam"></param> /// <param name="currentUser"></param> /// <returns></returns> public async Task <BaseResponseModel> ModifyRoleAsync(IncrementRoleParam incrementRoleParam, UserCacheBo currentUser) { var result = new ResponseModel <string>(); var db = SysRoleDao.CurrentDbContext; if (await db.SysRoles.AnyAsync(c => c.TenantId == currentUser.TenantId && !c.Deleted && c.RoleName == incrementRoleParam.RoleName && c.RoleId != incrementRoleParam.RoleId)) { return(result.Fail("角色名已存在")); } var checkResult = await RoleIdCheckAsync(incrementRoleParam.RoleId, currentUser); if (!checkResult.IsNullOrEmpty()) { return(result.Fail(checkResult)); } var role = await db.SysRoles.FirstOrDefaultAsync(c => !c.Deleted && c.RoleId == incrementRoleParam.RoleId && c.TenantId == currentUser.TenantId); role.RoleName = incrementRoleParam.RoleName; role.RoleDesc = incrementRoleParam.RoleDesc ?? ""; role.UpdatedBy = currentUser.UserId; role.UpdatedTime = DateTime.Now; var count = await db.SaveChangesAsync(); return(count > 0 ? result.Succeed("修改成功") : result.Fail("修改失败", "修改失败")); }
public ResponseModel GuardarReserva(Reservas reserva) { ResponseModel response = new ResponseModel(); try { if (reserva.FechaHoraPickup > reserva.FechaHoraDropoff) { throw new Exception($"La fecha de hora de Pickup debe ser menor que la fecha de Dropoff"); } Guid id = reserva.ReservaId; id = id == Guid.Empty ? Guid.NewGuid() : id; reserva.ReservaId = id; reserva.FechaCreacion = DateTime.Now; Validator <Reservas, ReservasValidator>(reserva); var newid = _data.InsertGetKey <Guid>(reserva); reserva = _data.ConsultarReservaPorId(id); response.SuccesCall(reserva, "Reserva guardada correctamente"); } catch (BusinessException ex) { response.Fail(ex); } catch (Exception ex) { response.Fail(ex, $"Error en => {nameof(GuardarReserva)}"); Logger.ErrorFatal($"ReservasServices {nameof(GuardarReserva)}", ex); } return(response); }
/// <summary> /// 发送验证码 - 找回密码 /// </summary> /// <param name="email"></param> /// <returns></returns> public async Task <ResponseModel <string> > SendEmailAsync(string email) { var response = new ResponseModel <string>(); if (!email.IsEmail()) { return(response.Fail("邮箱格式错误")); } var key = $"{CacheKeys.RETRIEVEPWDCAPTCHA}{email}"; var expireMinutes = 5; if (await FrequentlyGetCaptchaAsync(key, expireMinutes, 2)) { return(response.Fail("获取验证码过于频繁,请稍后再获取")); } if (!await ExistUserAsync(email)) { return(response.Fail("该邮箱尚未注册或无效")); } var captchaNumber = CaptchaHelper.CreateRandomNumber(6); var htmlEmail = SystemBll.GetMailContent("找回密码", captchaNumber, expireMinutes); var result = await SystemBll.SendSystemMailAsync("LionFrame-找回密码", htmlEmail, email); if (result.Contains("发送成功")) { await RedisClient.SetAsync(key, captchaNumber, new TimeSpan(0, expireMinutes, 0)); } return(response.Succeed("发送成功")); }
public virtual async Task <ResponseModel <bool> > ModifyManagerUserAsync(long uid, List <long> roleIds, string nickName, UserCacheBo currentUser) { var result = new ResponseModel <bool>(); var user = await CurrentDbContext.SysUsers.FirstOrDefaultAsync(c => c.UserId == uid && c.State == 1 && c.TenantId == currentUser.TenantId); if (user == null) { return(result.Fail("修改的用户信息不存在")); } if (user.CreatedBy == 0) { return(result.Fail("管理员只读")); } //获取当前用户所拥有的角色 var existRoleIds = await CurrentDbContext.SysUserRoleRelations.Where(c => c.UserId == uid && !c.Deleted && c.State == 1 && c.TenantId == currentUser.TenantId && c.CreatedBy > 0) .Select(c => c.RoleId).ToListAsync(); user.NickName = nickName; var dRoleIds = existRoleIds.Except(roleIds).ToList(); //删除此前分配的角色 不在这次保存角色中的 var iRoleIds = roleIds.Except(existRoleIds).ToList(); //插入这次新增的不在之前角色中的 //相同部分不做改变 if (dRoleIds.Any()) { // 删除 await CurrentDbContext.SysUserRoleRelations.Where(c => c.UserId == uid && dRoleIds.Contains(c.RoleId) && c.TenantId == currentUser.TenantId).DeleteFromQueryAsync(); } if (iRoleIds.Count > 0) { //插入 var userRoleRelations = new List <SysUserRoleRelation>(); iRoleIds.ForEach(roleId => { userRoleRelations.Add(new SysUserRoleRelation() { TenantId = currentUser.TenantId, CreatedBy = currentUser.UserId, CreatedTime = DateTime.Now, RoleId = roleId, State = 1, UserId = uid, }); }); await CurrentDbContext.SysUserRoleRelations.AddRangeAsync(userRoleRelations); } var count = await SaveChangesAsync(); return(count > 0 ? result.Succeed(true) : result.Fail("保存修改信息失败")); }
/// <summary> /// 添加一个工作调度 /// </summary> /// <param name="entity"></param> /// <returns></returns> public async Task <BaseResponseModel> AddScheduleJobAsync(ScheduleEntityParam entity) { var result = new ResponseModel <string>(); try { if (!await CheckScheduleEntityParam(entity, result)) { return(result); } var jobDataMap = new Dictionary <string, string>() { { QuartzConstant.NOTIFYEMAIL, entity.NotifyEmail }, { QuartzConstant.MAILMESSAGE, ((int)entity.MailMessage).ToString() }, { QuartzConstant.JOBTYPE, ((int)entity.JobType).ToString() }, { QuartzConstant.REQUESTPARAMETERS, entity.RequestParameters } //http Body 参数,Assembly 调用方法参数。 }; IJobDetail job; switch (entity.JobType) { case JobTypeEnum.Http: job = AddHttpJob(entity, jobDataMap); break; case JobTypeEnum.Assembly: job = AddAssemblyJob(entity, jobDataMap); break; case JobTypeEnum.None: default: return(result.Fail("未选择任务类型")); break; } //校验是否正确的执行周期表达式 var trigger = entity.TriggerType == TriggerTypeEnum.Cron ? CreateCronTrigger(entity) : CreateSimpleTrigger(entity); await Scheduler.ScheduleJob(job, trigger); result.Succeed("添加任务成功"); } catch (Exception ex) { LogHelper.Logger.Fatal(ex, "添加任务失败"); result.Fail(ResponseCode.UnknownEx, ex.Message, ""); } return(result); }
/// <summary> /// 用户管理界面创建用户 /// </summary> /// <param name="param"></param> /// <param name="currentUser"></param> /// <returns></returns> public async Task <BaseResponseModel> CreateManagerUserAsync(CreateUserParam param, UserCacheBo currentUser) { var result = new ResponseModel <bool>(); // 考虑是否验证上传的角色是当前租户下的 var checkResult = await CheckRoleIds(param.RoleIds, currentUser); if (!checkResult.IsNullOrEmpty()) { return(result.Fail(checkResult)); } if (await ExistUserAsync(param.Email)) { result.Fail(ResponseCode.Fail, "该邮箱已存在", false); return(result); } var sysUser = new SysUser() { NickName = param.NickName, PassWord = param.Pwd.Md5Encrypt(), Email = param.Email, Sex = 1, State = 1, CreatedTime = DateTime.Now, UpdatedTime = DateTime.Now, TenantId = currentUser.TenantId, UpdatedBy = 0, CreatedBy = currentUser.UserId, SysUserRoleRelations = new List <SysUserRoleRelation>() }; param.RoleIds.ForEach(roleId => { sysUser.SysUserRoleRelations.Add(new SysUserRoleRelation() { TenantId = currentUser.TenantId, RoleId = roleId, State = 1, CreatedTime = DateTime.Now, CreatedBy = currentUser.UserId, Deleted = false, }); }); SysUserDao.Add(sysUser); var count = await SysUserDao.SaveChangesAsync(); return(count > 0 ? result.Succeed(true) : result.Fail("保存失败", false)); }
public ResponseModel ModificarReserva(Reservas reserva) { ResponseModel response = new ResponseModel(); try { var reservaOld = _data.GetFindById(reserva.ReservaId); if (reservaOld == null) { throw new Exception($"No existe la reserva con id {reserva.ReservaId}"); } if (reserva.FechaHoraPickup > reserva.FechaHoraDropoff) { throw new Exception($"La fecha de hora de Pickup debe ser menor que la fecha de Dropoff"); } reservaOld.FechaHoraDropoff = reserva.FechaHoraDropoff; reservaOld.FechaHoraPickup = reserva.FechaHoraPickup; reservaOld.TipoIdentificacionId = reserva.TipoIdentificacionId; reservaOld.DocumentoIdentidad = reserva.DocumentoIdentidad; reservaOld.Apellidos = reserva.Apellidos; reservaOld.Nombres = reserva.Nombres; reservaOld.LugarDropoff = reserva.LugarDropoff; reservaOld.LugarPickup = reserva.LugarPickup; reservaOld.Marca = reserva.Marca; reservaOld.Modelo = reserva.Modelo; reservaOld.PrecioPorHora = reserva.PrecioPorHora; Validator <Reservas, ReservasValidator>(reservaOld); _data.Update(reservaOld); reservaOld = _data.ConsultarReservaPorId(reserva.ReservaId); response.SuccesCall(reservaOld, "Reserva modificada correctamente"); } catch (BusinessException ex) { response.Fail(ex); } catch (Exception ex) { response.Fail(ex, $"Error en => {nameof(ModificarReserva)}"); Logger.ErrorFatal($"ReservasServices {nameof(ModificarReserva)}", ex); } return(response); }
/// <summary> /// 暂停/删除 指定的计划 /// </summary> /// <param name="jobKey"></param> /// <param name="isDelete">停止并删除任务</param> /// <returns></returns> public async Task <BaseResponseModel> StopOrDelScheduleJobAsync(JobKey jobKey, bool isDelete = false) { var result = new ResponseModel <string>(); try { await Scheduler.PauseJob(jobKey); if (isDelete) { await Scheduler.DeleteJob(jobKey); result.Succeed("删除任务计划成功"); } else { result.Succeed("暂停任务计划成功"); } } catch (Exception ex) { result.Fail(ResponseCode.UnknownEx, "停止计划任务失败!--" + ex.Message, ""); } return(result); }
public async Task <ResponseModel <TokenDto> > CreateTokenByRefreshTokenAsync(string refreshToken) { var userRefreshToken = await _userRefreshTokenRepository.GetAllByFilter(p => p.Code.Equals(refreshToken)).SingleOrDefaultAsync(); if (userRefreshToken == null) { return(ResponseModel <TokenDto> .Fail("Refresh token not found", 404, true)); } var user = await _userManager.FindByIdAsync(userRefreshToken.UserId); if (user == null) { return(ResponseModel <TokenDto> .Fail("User not found", 404, true)); } var tokenDto = _tokenService.CreateToken(user); userRefreshToken.Code = tokenDto.RefreshToken; userRefreshToken.Expiration = tokenDto.RefreshTokenExpiration; _userRefreshTokenRepository.Update(userRefreshToken); await _unitOfWork.SaveChangesAsync(); return(ResponseModel <TokenDto> .Success(tokenDto, 200)); }
public static void UseCustomExceptionHandler(this IApplicationBuilder app) { app.UseExceptionHandler(options => { options.Run(async context => { context.Response.StatusCode = 500; context.Response.ContentType = "application/json"; var errorFeature = context.Features.Get <IExceptionHandlerFeature>(); if (errorFeature != null) { var exception = errorFeature.Error; ErrorDto errorDto = null; if (typeof(CustomException) == exception.GetType()) { errorDto = new ErrorDto(exception.Message, true); } else { errorDto = new ErrorDto(exception.Message, false); } var responseModel = ResponseModel <NoDataDto> .Fail(errorDto, 500); await context.Response.WriteAsync(JsonSerializer.Serialize(responseModel)) } }); }); }
/// <summary> /// 恢复运行暂停的任务 /// </summary> /// <param name="jobKey">任务</param> public async Task <BaseResponseModel> ResumeJobAsync(JobKey jobKey) { var result = new ResponseModel <string>(); try { //检查任务是否存在 if (await Scheduler.CheckExists(jobKey)) { //任务已经存在则暂停任务 await Scheduler.ResumeJob(jobKey); result.Succeed("恢复任务计划成功"); } else { result.Succeed("任务不存在"); } } catch (Exception ex) { result.Fail(ResponseCode.UnknownEx, "恢复任务计划失败!--" + ex.Message, ""); LogHelper.Logger.Error($"恢复任务失败!{ex}"); } return(result); }
/// <summary> /// 修改菜单 /// </summary> /// <param name="currentUser"></param> /// <param name="incrementMenu"></param> /// <returns></returns> public async Task <BaseResponseModel> UpdateMenuAsync(UserCacheBo currentUser, IncrementMenuParam incrementMenu) { var responseModel = new ResponseModel <bool>(); var count = await SysMenuDao.UpdateMenuAsync(currentUser, incrementMenu); return(count ? responseModel.Succeed(true) : responseModel.Fail(ResponseCode.Fail, "修改失败")); }
/// <summary> /// 登录 /// </summary> /// <param name="loginParam"></param> /// <returns></returns> public async Task <ResponseModel <UserCacheBo> > LoginAsync(LoginParam loginParam) { CloseTracking(); var response = new ResponseModel <UserCacheBo>(); var user = await FirstAsync <SysUser>(c => c.Email == loginParam.Email && c.State == 1); if (user == null) { return(response.Fail(ResponseCode.LoginFail, "账号不存在", null)); } if (user.PassWord != loginParam.Password.Md5Encrypt()) { return(response.Fail(ResponseCode.LoginFail, "账号或密码错误", null)); } var dbData = from sysUser in CurrentDbContext.SysUsers where sysUser.UserId == user.UserId && sysUser.State == 1 select new UserCacheBo { UserId = sysUser.UserId, TenantId = sysUser.TenantId, NickName = sysUser.NickName, PassWord = sysUser.PassWord, Email = sysUser.Email, Sex = sysUser.Sex, CreatedBy = sysUser.CreatedBy, RoleCacheBos = from userRoleRelation in CurrentDbContext.SysUserRoleRelations join sysRole in CurrentDbContext.SysRoles on userRoleRelation.RoleId equals sysRole.RoleId where userRoleRelation.UserId == sysUser.UserId && !userRoleRelation.Deleted && !sysRole.Deleted && userRoleRelation.State == 1 select new RoleCacheBo() { RoleId = sysRole.RoleId, TenantId = sysRole.TenantId, RoleDesc = sysRole.RoleDesc, RoleName = sysRole.RoleName, } }; // 使用include 无法使用条件判断 //var dbData1 = CurrentDbContext.SysUsers.Where(c => c.UserId == user.UserId && c.Status == 1).Include(c => c.SysUserRoleRelations).ThenInclude(c => c.SysRole).FirstOrDefault(); //var userCacheBo = dbData1.MapTo<UserCacheBo>(); response.Succeed(await dbData.FirstOrDefaultAsync()); return(response); }
public ResponseModel ConsultarReservaPorId(Guid reservaId) { ResponseModel response = new ResponseModel(); try { var reserva = _data.ConsultarReservaPorId(reservaId); response.SuccesCall(reserva); } catch (BusinessException ex) { response.Fail(ex); } catch (Exception ex) { response.Fail(ex, $"Error en => {nameof(ConsultarReservaPorId)}"); Logger.ErrorFatal($"ReservasServices {nameof(ConsultarReservaPorId)}", ex); } return(response); }
public async Task <ResponseModel <TDto> > GetByIdAsync(int id) { var entity = await _repository.GetByIdAsync(id); if (entity == null) { return(ResponseModel <TDto> .Fail("Id not found!", 404, true)); } var dto = ObjectMapper.Mapper.Map <TDto>(entity); return(ResponseModel <TDto> .Success(dto, 200)); }
public async Task <ResponseModel <UserDto> > GetUserByName(string userName) { var user = await _userManager.FindByNameAsync(userName); if (user == null) { return(ResponseModel <UserDto> .Fail("UserName not found!", 404, true)); } var userDto = ObjectMapper.Mapper.Map <UserDto>(user); return(ResponseModel <UserDto> .Success(userDto, 200)); }
public ResponseModel ConsultarReservas(ReservaFiltro filtro) { ResponseModel response = new ResponseModel(); try { filtro.ReservaId = null; var reservas = _data.ConsultarReservas(filtro); response.SuccesCall(reservas); } catch (BusinessException ex) { response.Fail(ex); } catch (Exception ex) { response.Fail(ex, $"Error en => {nameof(ConsultarReservas)}"); Logger.ErrorFatal($"ReservasServices {nameof(ConsultarReservas)}", ex); } return(response); }
public virtual async Task <BaseResponseModel> RemoveRoleAsync(long roleId, UserCacheBo currentUser) { var result = new ResponseModel <string>(); var db = SysRoleDao.CurrentDbContext; var checkResult = await RoleIdCheckAsync(roleId, currentUser); if (!checkResult.IsNullOrEmpty()) { return(result.Fail(checkResult)); } var count = await db.SysRoles.Where(c => c.RoleId == roleId && !c.Deleted).DeleteFromQueryAsync(); count += await db.SysUserRoleRelations.Where(c => c.RoleId == roleId).DeleteFromQueryAsync(); count += await db.SysRoleMenuRelations.Where(c => c.RoleId == roleId).DeleteFromQueryAsync(); count += await db.SaveChangesAsync(); return(count > 0 ? result.Succeed("角色删除成功") : result.Fail("角色删除失败")); }
public ResponseModel <ClientTokenDto> CreateTokenByClient(ClientLoginDto clientLoginDto) { var client = _clients.SingleOrDefault(p => p.Id.Equals(clientLoginDto.ClientId, StringComparison.OrdinalIgnoreCase) && p.Secret.Equals(clientLoginDto.ClientSecret, StringComparison.OrdinalIgnoreCase)); if (client == null) { return(ResponseModel <ClientTokenDto> .Fail("Client id or ClientSecret not found!", 404, true)); } var token = _tokenService.CreateTokenByClient(client); return(ResponseModel <ClientTokenDto> .Success(token, 200)); }
private Task ErrorResponse(HttpContext ctx, int statusCode, HftApiErrorCode code, string message, Dictionary <string, string> fields = null) { ctx.Response.ContentType = "application/json"; ctx.Response.StatusCode = statusCode; var response = ResponseModel.Fail(code, message, fields ?? new Dictionary <string, string>()); return(ctx.Response.WriteAsync(JsonConvert.SerializeObject(response, new JsonSerializerSettings { ContractResolver = new CamelCasePropertyNamesContractResolver() }))); }
/// <summary> /// 取消分配菜单 /// </summary> /// <param name="menuIds"></param> /// <param name="uid"></param> /// <returns></returns> public async Task <BaseResponseModel> CancelAssignMenuAsync(List <string> menuIds, long uid) { var count = await SysRoleMenuRelationDao.CurrentDbContext.SysRoleMenuRelations.Where(c => menuIds.Contains(c.MenuId) && c.RoleId != 1).UpdateFromQueryAsync(c => new SysRoleMenuRelation() { Deleted = true, UpdatedBy = uid, UpdatedTime = DateTime.Now, }); var result = new ResponseModel <bool>(); return(count > 0 ? result.Succeed(true) : result.Fail("分配菜单失败")); }
public virtual async Task <BaseResponseModel> ModifyRoleMenuAsync(ModifyRoleMenuParam roleMenuParam, UserCacheBo currentUser) { var result = new ResponseModel <string>(); var checkResult = await RoleIdCheckAsync(roleMenuParam.RoleId, currentUser); if (!checkResult.IsNullOrEmpty()) { return(result.Fail(checkResult)); } var currentUserMenus = await MenuBll.GetCurrentMenuAsync(currentUser); var currentMenuIds = currentUserMenus.Select(c => c.MenuId).ToList(); //检查提交的按钮是否存在当前用户管理菜单数据中,只操作存在部分 即交集 var crossMenuIds = roleMenuParam.MenuIds.Intersect(currentMenuIds).ToList(); // 这里不是做的全量操作,而且新增部分做插入 数据库中的不在提交数据中的部分做删除 提交的和数据库相交叉的部分不做变动 var dbMenuIds = await SysMenuDao.LoadEntities <SysRoleMenuRelation>(c => c.RoleId == roleMenuParam.RoleId && c.TenantId == currentUser.TenantId).Select(c => c.MenuId).ToListAsync(); var dIds = dbMenuIds.Except(crossMenuIds).ToList(); //需要删除的权限 var iIds = crossMenuIds.Except(dbMenuIds).ToList(); //需要插入的新权限 var db = SysRoleDao.CurrentDbContext; if (dIds.Count > 0) { await db.SysRoleMenuRelations.Where(c => dIds.Contains(c.MenuId) && c.RoleId == roleMenuParam.RoleId).DeleteAsync(); } if (iIds.Count > 0) { var roleMenuRelations = iIds.Select(iId => new SysRoleMenuRelation() { TenantId = currentUser.TenantId, CreatedBy = currentUser.UserId, CreatedTime = DateTime.Now, MenuId = iId, State = 1, Deleted = false, RoleId = roleMenuParam.RoleId, UpdatedBy = 0, UpdatedTime = DateTime.Now, }).ToList(); await db.SysRoleMenuRelations.AddRangeAsync(roleMenuRelations); } await db.SaveChangesAsync(); return(result.Succeed("修改成功")); }
public async Task <ResponseModel <NoDataDto> > RevokeRefreshTokenAsync(string refreshToken) { var userRefreshToken = await _userRefreshTokenRepository.GetAllByFilter(p => p.Code.Equals(refreshToken)).SingleOrDefaultAsync(); if (userRefreshToken == null) { return(ResponseModel <NoDataDto> .Fail("Refresh token not found", 404, true)); } _userRefreshTokenRepository.Remove(userRefreshToken); await _unitOfWork.SaveChangesAsync(); return(ResponseModel <NoDataDto> .Success(200)); }
public async Task <ResponseModel <NoDataDto> > Remove(int id) { var entity = await _repository.GetByIdAsync(id); if (entity == null) { return(ResponseModel <NoDataDto> .Fail("Entity Not Found!", 404, true)); } _repository.Remove(entity); await _unitOfWork.SaveChangesAsync(); return(ResponseModel <NoDataDto> .Success(204)); }
public async Task <ResponseModel <NoDataDto> > Update(TDto dto, int id) { var entity = await _repository.GetByIdAsync(id); if (entity == null) { return(ResponseModel <NoDataDto> .Fail("Entity Not Found!", 404, true)); } var entityForDto = ObjectMapper.Mapper.Map <TEntity>(dto); _repository.Update(entityForDto); await _unitOfWork.SaveChangesAsync(); return(ResponseModel <NoDataDto> .Success(204)); }
public virtual async Task <BaseResponseModel> DeleteMenuAsync(string menuId) { var result = new ResponseModel <string>(); var db = SysMenuDao.CurrentDbContext; var isExistChildren = await db.SysMenus.AnyAsync(c => c.ParentMenuId == menuId); if (isExistChildren) { return(result.Fail("请先删除子菜单后再删除父菜单")); } await db.SysMenus.Where(c => c.MenuId == menuId).DeleteFromQueryAsync(); await db.SysRoleMenuRelations.Where(c => c.MenuId == menuId).DeleteFromQueryAsync(); return(result.Succeed("删除成功")); }