/// <summary> /// 查询称号列表 /// </summary> /// <param name="user"></param> /// <param name="periodId"></param> /// <param name="requestAborted"></param> /// <returns></returns> public async Task <ResponseMessage <List <SearchTitleResponse> > > SearchTitleAsync(UserInfo user, string periodId, CancellationToken requestAborted) { var response = new ResponseMessage <List <SearchTitleResponse> >(); if (!user.IsAdmin) { response.Code = ResponseCodeDefines.NotAllow; response.Message = "权限不足"; return(response); } response.Extension = await _iTitleStore.GetScoreTitles().Where(w => w.PeriodId == periodId && !w.IsDelete).Select(s => new SearchTitleResponse { Id = s.Id, PeriodId = s.PeriodId, Title = s.Title, StartScore = s.StartScore, EndScore = s.EndScore, Icon = _config["FileUrl"] + s.Icon, Card = _config["FileUrl"] + s.Card, CreateTime = s.CreateTime, CreateUser = s.CreateUser, UpdateTime = s.UpdateTime, UpdateUser = s.UpdateUser, FontColor = s.FontColor, }).OrderBy(o => o.StartScore).ToListAsync(); return(response); }
/// <summary> /// 添加赛季 /// </summary> /// <returns></returns> public async Task <ResponseMessage> CreatePeriod(UserInfo userInfo, CreatePeriodRequest createPeriodRequest) { var response = new ResponseMessage(); var scorePeriod = new Period(); scorePeriod.Id = Guid.NewGuid().ToString(); scorePeriod.IsDelete = false; scorePeriod.Memo = createPeriodRequest.Memo; scorePeriod.StartDate = createPeriodRequest.StartDate; scorePeriod.Caption = createPeriodRequest.Caption; scorePeriod.CreateTime = DateTime.Now; scorePeriod.CreateUser = userInfo.Id; scorePeriod.UpdateTime = DateTime.Now; scorePeriod.UpdateUser = userInfo.Id; scorePeriod.State = 0; scorePeriod.EndDate = createPeriodRequest.EndDate; scorePeriod.PlayingUrl = createPeriodRequest.PlayingUrl; scorePeriod.SystemUrl = createPeriodRequest.SystemUrl; //复制一份上一个赛季的称号信息 //先查询有没有进行中的赛季 var periods = await _rankTitleStore.GetScorePeriods().Where(w => !w.IsDelete && w.State == 1).FirstOrDefaultAsync(); var rankInfoList = new List <RankTitle>(); if (periods == null) { //在查询上一个赛季 periods = await _rankTitleStore.GetScorePeriods().Where(w => !w.IsDelete).OrderByDescending(o => o.EndDate).FirstOrDefaultAsync(); } if (periods != null) { rankInfoList = await _rankTitleStore.GetScoreTitles().Where(w => !w.IsDelete && w.PeriodId == periods.Id).ToListAsync(); rankInfoList.ForEach(fo => { fo.Id = Guid.NewGuid().ToString(); fo.PeriodId = scorePeriod.Id; fo.UpdateTime = DateTime.Now; fo.UpdateUser = userInfo.Id; fo.CreateTime = DateTime.Now; fo.CreateUser = userInfo.Id; }); } //事务保存 using (var trans = await _transaction.BeginTransaction()) { try { if (rankInfoList.Any()) { await _rankTitleStore.AddTitleListAsync(rankInfoList); } await _scorePeriodStore.CreatePeriodAsync(scorePeriod); trans.Commit(); } catch (Exception e) { trans.Rollback(); throw new Exception("保存事务失败", e); } } // 触发赛季 await _sendClientMessageManager.SendInfo(Dto.Common.SendClientType.Season); return(response); }