public static T FirstOrThrow_ <T>(this IQueryable <T> query, string error_msg) { var model = query.FirstOrDefault(); Com.AssertNotNull(model, error_msg); return(model); }
public async Task <string> UpdateScopeAsync(AuthScope updatemodel) { var scope = await this._AuthScopeRepository.GetFirstAsync(x => x.UID == updatemodel.UID); Com.AssertNotNull(scope, $"找不到scope[scope_uid={updatemodel.UID}]"); //scope.Name = updatemodel.Name; scope.DisplayName = updatemodel.DisplayName; scope.Description = updatemodel.Description; scope.Important = updatemodel.Important; scope.Sort = updatemodel.Sort; scope.IsDefault = updatemodel.IsDefault; scope.ImageUrl = updatemodel.ImageUrl; scope.FontIcon = updatemodel.FontIcon; scope.UpdateTime = DateTime.Now; if (!this.CheckModel(scope, out var msg)) { return(msg); } if (await this._AuthScopeRepository.UpdateAsync(scope) > 0) { this._publisher.EntityUpdated(scope); return(SUCCESS); } throw new MsgException("更新scope失败"); }
public virtual async Task <_ <UserBase> > ActiveOrDeActiveUser(string uid, bool active) { var data = new _ <UserBase>(); var user = await this._userRepo.GetFirstAsync(x => x.UID == uid); Com.AssertNotNull(user, $"用户不存在:{uid}"); if (user.IsActive.ToBool() == active) { data.SetErrorMsg("状态不需要改变"); return(data); } user.IsActive = active.ToBoolInt(); user.Update(); if (!user.IsValid(out var msg)) { data.SetErrorMsg(msg); return(data); } if (await this._userRepo.UpdateAsync(user) > 0) { data.SetSuccessData(user); return(data); } throw new Exception("操作失败"); }
public static async Task <T> FirstOrThrowAsync <T>(this IQueryable <T> query, string error_msg) { var model = await query.FirstOrDefaultAsync(); Com.AssertNotNull(model, error_msg); return(model); }
public async Task <string> ApproveClient(string client_uid, bool active, string reason) { var model = await this._AuthClientRepository.GetFirstAsync(x => x.UID == client_uid); Com.AssertNotNull(model, $"can not find client by uid:{client_uid}"); var active_data = active.ToString().ToBoolInt(); if (model.IsActive == active_data) { return("状态无需改变"); } model.IsActive = active_data; if (await this._AuthClientRepository.UpdateAsync(model) > 0) { var log = new AuthClientCheckLog(); log.Init("clientchecklog"); log.CheckStatus = model.IsActive; log.Msg = reason ?? "no reason"; if (await this._AuthClientCheckLogRepository.AddAsync(log) <= 0) { $"{model.ToJson()}保存操作日志失败{log.ToJson()}".AddBusinessInfoLog(); } return(SUCCESS); } throw new Exception("更新client失败"); }
public virtual async Task <_ <string> > UpdateEvent(CalendarEventEntity model) { var data = new _ <string>(); var e = await this._calendarRepo.GetFirstAsync(x => x.UID == model.UID); Com.AssertNotNull(e, "事件不存在"); e.Summary = model.Summary; e.Content = model.Content; e.RRule = model.RRule; e.HasRule = ValidateHelper.IsPlumpString(model.RRule).ToBoolInt(); e.DateStart = model.DateStart.Date; e.DateEnd = model.DateEnd?.Date; e.Update(); if (!e.IsValid(out var msg)) { data.SetErrorMsg(msg); return(data); } if (await this._calendarRepo.GetCountAsync(x => x.OrgUID == model.OrgUID && x.HasRule > 0 && x.UID != model.UID) >= await this.GetMaxRRuleCount(e.OrgUID)) { data.SetErrorMsg("规则数量达到上限"); return(data); } if (await this._calendarRepo.UpdateAsync(e) > 0) { data.SetSuccessData(string.Empty); return(data); } throw new Exception("更新失败"); }
public static async Task AddJob_(this IScheduler manager, Type t, ITrigger trigger, string name, string group = null, bool throw_if_exist = true) { Com.AssertNotNull(t, nameof(t)); Com.AssertNotNull(t, nameof(trigger)); Com.AssertNotNull(t, nameof(name)); var builder = JobBuilder.Create(t); if (ValidateHelper.IsPlumpString(group)) { builder = builder.WithIdentity(name, group); } else { builder = builder.WithIdentity(name); } var job = builder.Build(); if ((await manager.GetAllJobKeys_()).Contains(job.Key)) { if (throw_if_exist) { throw new Exception("job已经存在"); } else { return; } } await manager.ScheduleJob(job, trigger); }
public virtual async Task <_ <string> > OpenOrClose(string issue_uid, string user_uid, bool close) { return(await this._issueRepo.PrepareSessionAsync(async db => { var query = db.Set <IssueEntity>().AsQueryable(); var res = new _ <string>(); var now = DateTime.Now; var issue = await query.FirstOrDefaultAsync(x => x.UID == issue_uid); Com.AssertNotNull(issue, "issue is null"); if (issue.AssignedUserUID != user_uid && issue.UserUID != user_uid) { res.SetErrorMsg("无权操作"); return res; } var status = close.ToBoolInt(); if (issue.IsClosed == status) { res.SetErrorMsg("状态无需改变"); return res; } issue.IsClosed = status; if (close) { var seconds = (int)(now - (issue.Start ?? issue.CreateTime)).TotalSeconds; if (seconds >= 0) { //处理问题花了多长时间 issue.SecondsToTakeToClose = seconds; } } else { issue.SecondsToTakeToClose = 0; } var log = new IssueOperationLogEntity() { UserUID = user_uid, OrgUID = issue.OrgUID, IssueUID = issue.UID, IsClosed = issue.IsClosed, Operation = close ? "close" : "open", Content = string.Empty }.InitSelf("op"); db.Set <IssueOperationLogEntity>().Add(log); await db.SaveChangesAsync(); res.SetSuccessData(string.Empty); return res; })); }
public virtual async Task <_ <string> > OpenOrClose(string org_uid, string uid, bool close, string user_uid, string comment) { var res = new _ <string>(); var model = await this._issueRepo.GetFirstAsync(x => x.UID == uid); Com.AssertNotNull(model, "issue不存在"); if (model.OrgUID != org_uid) { res.SetErrorMsg("无权操作"); return(res); } var status = close.ToBoolInt(); if (model.IsClosed == status) { res.SetErrorMsg("状态无需改变"); return(res); } model.IsClosed = status; if (close) { model.SecondsToTakeToClose = (int)(DateTime.Now - model.CreateTime).TotalSeconds; } else { model.SecondsToTakeToClose = 0; } await this._issueRepo.UpdateAsync(model); //add log var operation_log = new IssueOperationLogEntity() { OrgUID = model.OrgUID, IssueUID = model.UID, IsClosed = model.IsClosed, UserUID = user_uid, Content = comment }.InitSelf("iol"); if (!operation_log.IsValid(out var msg)) { res.SetErrorMsg(msg); return(res); } await this._issueOperaRepo.AddAsync(operation_log); res.SetSuccessData(string.Empty); return(res); }
public async Task <string> DeleteClientAsync(string client_uid, string user_uid) { var client = await this._AuthClientRepository.GetFirstAsync(x => x.UID == client_uid && x.UserUID == user_uid); Com.AssertNotNull(client, $"找不到client[client_uid={client_uid},user_uid={user_uid}]"); if (await this._AuthClientRepository.DeleteAsync(client) > 0) { return(SUCCESS); } throw new Exception("删除client异常"); }
public async Task <string> DeleteScopeAsync(string scope_uid) { var scope = await this._AuthScopeRepository.GetFirstAsync(x => x.UID == scope_uid); Com.AssertNotNull(scope, $"找不到scope[scope_uid={scope_uid}]"); if (await this._AuthScopeRepository.DeleteAsync(scope) > 0) { this._publisher.EntityDeleted(scope); return(SUCCESS); } throw new MsgException("删除scope失败"); }
public virtual async Task <_ <DepartmentBase> > UpdateDepartment(DepartmentBase model) { var data = new _ <DepartmentBase>(); var department = await this._departmentRepo.GetFirstAsync(x => x.UID == model.UID); Com.AssertNotNull(department, "部门不存在"); this.UpdateDepartmentEntity(ref department, ref model); department.Update(); if (await this._departmentRepo.UpdateAsync(department) > 0) { data.SetSuccessData(department); return(data); } throw new Exception("更新部门失败"); }
public virtual async Task <_ <string> > SetRolePermissions(string role_uid, List <RolePermissionBase> permissions) { Com.AssertNotNull(permissions, "权限参数不能为空"); var data = new _ <string>(); //检查参数 if (permissions.Any(x => x.RoleID != role_uid)) { data.SetErrorMsg("角色ID错误"); return(data); } //旧的权限 var old_per = await this._rolePermissionRepo.GetListAsync(x => x.RoleID == role_uid); //要更新的数据 var update = old_per.UpdateList(permissions, x => x.UID); //等待添加 if (ValidateHelper.IsPlumpList(update.WaitForAdd)) { var add_list = permissions.Where(x => update.WaitForAdd.Contains(x.UID)).ToList(); foreach (var m in add_list) { m.Init("per"); if (!m.IsValid(out var msg)) { data.SetErrorMsg(msg); return(data); } } await this._rolePermissionRepo.AddAsync(add_list.ToArray()); } //等待删除 if (ValidateHelper.IsPlumpList(update.WaitForDelete)) { var delete_list = update.WaitForDelete.ToList(); await this._rolePermissionRepo.DeleteWhereAsync(x => delete_list.Contains(x.UID)); } data.SetSuccessData(string.Empty); return(data); }
public async Task <string> EnableOrDisableClientAsync(string client_uid, string user_uid) { var client = await this._AuthClientRepository.GetFirstAsync(x => x.UID == client_uid && x.UserUID == user_uid); Com.AssertNotNull(client, $"找不到client[client_uid={client_uid},user_uid={user_uid}]"); client.IsRemove = (!client.IsRemove.ToBool()).ToBoolInt(); client.UpdateTime = DateTime.Now; if (!this.CheckModel(client, out var msg)) { return(msg); } ; if (await this._AuthClientRepository.UpdateAsync(client) > 0) { return(SUCCESS); } throw new MsgException("更新client激活状态异常"); }
public virtual async Task <_ <string> > UpdateMenu(MenuBase model) { var data = new _ <string>(); var menu = await this._menuRepo.GetFirstAsync(x => x.UID == model.UID); Com.AssertNotNull(menu, "菜单不存在"); menu.Update(); if (!menu.IsValid(out var msg)) { data.SetErrorMsg(msg); return(data); } if (await this._menuRepo.UpdateAsync(menu) > 0) { data.SetSuccessData(string.Empty); return(data); } throw new Exception("更新菜单错误"); }
public virtual async Task <_ <string> > UpdateOrg(OrgBase model) { var data = new _ <string>(); var org = await this._orgRepo.GetFirstAsync(x => x.UID == model.UID); Com.AssertNotNull(org, "组织不存在"); this.UpdateOrgEntity(ref org, ref model); org.Update(); if (!org.IsValid(out var msg)) { data.SetErrorMsg(msg); return(data); } if (await this._orgRepo.UpdateAsync(org) > 0) { data.SetSuccessData(string.Empty); return(data); } throw new Exception("更新组织失败"); }
public virtual async Task <_ <string> > UpdateMenuGroup(MenuGroupBase model) { var data = new _ <string>(); var group = await this._menuGroupRepo.GetFirstAsync(x => x.UID == model.UID); Com.AssertNotNull(group, "分组不存在"); this.UpdateMenuGroupEntity(ref group, ref model); group.Update(); if (!group.IsValid(out var msg)) { data.SetErrorMsg(msg); return(data); } if (await this._menuGroupRepo.UpdateAsync(group) > 0) { data.SetSuccessData(string.Empty); return(data); } throw new Exception("更新失败"); }
public virtual async Task <_ <string> > UpdatePage(PageBase model) { var data = new _ <string>(); var page = await this._pageRepo.GetFirstAsync(x => x.UID == model.UID); Com.AssertNotNull(page, "页面不存在"); this.UpdatePageEntity(ref page, ref model); page.Update(); if (!page.IsValid(out var msg)) { data.SetErrorMsg(msg); return(data); } if (await this._pageRepo.UpdateAsync(page) > 0) { data.SetSuccessData(string.Empty); return(data); } throw new Exception("更新页面失败"); }
public virtual async Task <_ <PermissionBase> > UpdatePermission(PermissionBase model) { var data = new _ <PermissionBase>(); var permission = await this._permissionRepo.GetFirstAsync(x => x.UID == model.UID); Com.AssertNotNull(permission, $"权限为空:{model.UID}"); this.UpdatePermissionEntity(ref permission, ref model); permission.Update(); if (!permission.IsValid(out var msg)) { data.SetErrorMsg(msg); return(data); } if (await this._permissionRepo.UpdateAsync(permission) > 0) { data.SetSuccessData(permission); return(data); } throw new Exception("更新权限错误"); }
public async Task <string> UpdateClientAsync(AuthClient updatemodel) { var client = await this._AuthClientRepository.GetFirstAsync(x => x.UID == updatemodel.UID && x.UserUID == updatemodel.UserUID); Com.AssertNotNull(client, $"client不存在:{updatemodel.ToJson()}"); client.ClientName = updatemodel.ClientName; client.ClientUrl = updatemodel.ClientUrl; client.LogoUrl = updatemodel.LogoUrl; client.UpdateTime = DateTime.Now; if (!this.CheckModel(client, out var msg)) { return(msg); } if (await this._AuthClientRepository.UpdateAsync(client) > 0) { return(SUCCESS); } throw new MsgException("更新client异常"); }
public virtual async Task <_ <string> > UpdateRole(RoleBase model) { var data = new _ <string>(); var role = await this._roleRepo.GetFirstAsync(x => x.UID == model.UID); Com.AssertNotNull(role, $"角色不存在:{model.UID}"); this.UpdateRoleEntity(ref role, ref model); role.Update(); if (!role.IsValid(out var msg)) { data.SetErrorMsg(msg); return(data); } if (await this._roleRepo.UpdateAsync(role) > 0) { data.SetSuccessData(string.Empty); return(data); } throw new Exception("更新角色失败"); }
public virtual async Task <_ <OrganizationEntity> > UpdateOrg(OrganizationEntity model) { var res = new _ <OrganizationEntity>(); var entity = await this._orgRepo.GetFirstAsync(x => x.UID == model.UID); Com.AssertNotNull(entity, "组织不存在"); this.UpdateOrgEntity(ref entity, ref model); entity.Update(); if (!entity.IsValid(out var msg)) { res.SetErrorMsg(msg); return(res); } await this._orgRepo.UpdateAsync(entity); res.SetSuccessData(entity); return(res); }
public virtual async Task <_ <UserBase> > ChangePwd(UserBase model) { var data = new _ <UserBase>(); var user = await this._userRepo.GetFirstAsync(x => x.UID == model.UID); Com.AssertNotNull(user, "用户不存在,无法修改密码"); user.PassWord = this.EncryptPassword(model.PassWord); user.Update(); if (!user.IsValid(out var msg)) { data.SetErrorMsg(msg); return(data); } if (await this._userRepo.UpdateAsync(user) > 0) { data.SetSuccessData(user); return(data); } throw new Exception("密码修改失败"); }
public virtual async Task <_ <UserBase> > UpdateUser(UserBase model) { var data = new _ <UserBase>(); var user = await this._userRepo.GetFirstAsync(x => x.UID == model.UID); Com.AssertNotNull(user, $"用户不存在:{model.UID}"); this.UpdateUserEntity(ref user, ref model); user.Update(); if (!user.IsValid(out var msg)) { data.SetErrorMsg(msg); return(data); } if (await this._userRepo.UpdateAsync(user) > 0) { data.SetSuccessData(user); return(data); } throw new Exception("更新失败"); }