Beispiel #1
0
 public async Task <IActionResult> AddOrChange([FromBody] ShardingConfigAddOrChangeRequest request)
 {
     try
     {
         ShardingConfigAddOrChangeResponse response = new ShardingConfigAddOrChangeResponse();
         var results = ShardingConfigAddRequestValidator.ValidateModel(request);
         if (results.IsValid)
         {
             results = ShardingConfigAddModelValidator.ValidateModel(request.ShardingConfig);
             if (results.IsValid)
             {
                 response = await _shardingAppService.ShardingConfigAddOrChange(request);
             }
             else
             {
                 response.SetFail(results.Errors.Select(p => p.ToString()));
             }
         }
         else
         {
             response.SetFail(results.Errors.Select(p => p.ToString()));
         }
         return(Json(response));
     }
     catch (Exception e)
     {
         _logger.LogError(e, Common.Common.GetMethodName(), request);
         throw;
     }
 }
Beispiel #2
0
        public async Task <ShardingConfigAddOrChangeResponse> ShardingConfigAddOrChange(ShardingConfigAddOrChangeRequest request)
        {
            ShardingConfigAddOrChangeResponse response = new ShardingConfigAddOrChangeResponse();

            try
            {
                ShardingConfig shardingConfig = request.ShardingConfig.ToObject();
                if (shardingConfig.Id > 0)
                {
                    shardingConfig.UpdatedDate = Extensions.GetCurrentDateUtc();
                    await _shardingService.Change(shardingConfig);
                }
                else
                {
                    //var loginInfo =await _userService.GetLoginInfo(request.SessionId);
                    //shardingConfig.CreatedUid = loginInfo.Id;
                    shardingConfig.CreatedDate = Extensions.GetCurrentDateUtc();
                    await _shardingService.Add(shardingConfig);
                }
                response.SetSucess();
            }
            catch (Exception e)
            {
                response.SetFail(e);
                _logger.LogError(e, e.Message, request);
            }
            return(response);
        }