/// <summary> /// 赛季奖品管理-新增/修改赛季奖品 /// </summary> /// <param name="user"></param> /// <param name="request"></param> /// <param name="requestAborted"></param> /// <returns></returns> public async Task <ResponseMessage> GiftAddOrUpdateAsync(UserInfo user, GiftAddRequest request, CancellationToken requestAborted) { var response = new ResponseMessage(); if (string.IsNullOrWhiteSpace(request.Id)) { var giftQuery = _giftStore.GetGiftInfos().Where(w => !w.IsDelete && w.PeriodId == request.PeriodId); if ((giftQuery.Sum(s => s.Odds) + request.Odds) > 1000) { response.Code = ResponseCodeDefines.ModelStateInvalid; response.Message = "中奖几率总和不能大于1000"; return(response); } if (giftQuery.Count() >= 8) { response.Code = ResponseCodeDefines.ModelStateInvalid; response.Message = "每个赛季礼品数量最多8个"; return(response); } var giftInfo = new GiftInfo { Id = Guid.NewGuid().ToString(), PeriodId = request.PeriodId, CreateTime = DateTime.Now, CreateUser = user.Id, IsDelete = false, Name = request.Name, Number = request.Number, Odds = request.Odds, ImageUrl = request.ImageUrl.Replace(_config["FileUrl"], ""), IsGet = request.IsGet, GetScore = request.GetScore, Order = request.Order }; await _giftStore.AddGift(giftInfo, requestAborted); } else { var giftInfo = await _giftStore.GetGiftInfos().Where(w => !w.IsDelete && w.PeriodId == request.PeriodId && w.Id == request.Id).FirstOrDefaultAsync(); if (giftInfo == null) { response.Code = ResponseCodeDefines.ModelStateInvalid; response.Message = "未找到对应的奖品信息"; return(response); } giftInfo.PeriodId = request.PeriodId; giftInfo.Name = request.Name; giftInfo.Number = request.Number; giftInfo.Odds = request.Odds; giftInfo.ImageUrl = request.ImageUrl.Replace(_config["FileUrl"], ""); giftInfo.IsGet = request.IsGet; giftInfo.GetScore = request.GetScore; giftInfo.Order = request.Order; await _giftStore.UpdateGift(giftInfo, requestAborted); } return(response); }
public async Task <ResponseMessage> GiftAddOrUpdate(Models.UserInfo user, [FromBody] GiftAddRequest request) { Logger.Trace($"用户{user?.UserName ?? ""}({user?.Id ?? ""})赛季奖品管理-新增/修改赛季奖品,请求参数为:\r\n" + (request != null ? JsonHelper.ToJson(request) : "")); var response = new ResponseMessage(); if (!ModelState.IsValid) { response.Code = ResponseCodeDefines.ModelStateInvalid; response.Message = "模型验证失败:" + ModelState.GetAllErrors(); Logger.Warn("赛季奖品管理-新增/修改赛季奖品,模型验证失败:\r\n{0}", response.Message ?? ""); return(response); } try { response = await _giftManager.GiftAddOrUpdateAsync(user, request, HttpContext.RequestAborted); } catch (Exception e) { response.Code = ResponseCodeDefines.ServiceError; response.Message = e.Message; Logger.Error($"用户{user?.UserName ?? ""}({user?.Id ?? ""})赛季奖品管理-新增/修改赛季奖品,报错:{e.Message}\r\n{e.StackTrace}"); } return(response); }