public async Task <LanguageAddOrChangeResponse> AddOrChange(LanguageAddOrChangeRequest request) { LanguageAddOrChangeResponse response = new LanguageAddOrChangeResponse(); try { CommandResult result; if (string.IsNullOrEmpty(request.Id.AsString())) { var command = request.ToCommand(_context.Ip); result = await _languageService.SendCommand(command); } else { var command = request.ToCommand(_context.Ip, request.Version); result = await _languageService.SendCommand(command); } if (result.IsSucess) { response.SetSucess(); } else { response.SetFail(result.Message); } } catch (Exception e) { response.SetFail(e); _logger.LogError(e, e.Message, request); } return(response); }
public async Task <IActionResult> Add([FromBody] LanguageAddOrChangeRequest request) { try { LanguageAddOrChangeResponse response = new LanguageAddOrChangeResponse(); ValidationResult validate = LanguageAddOrChangeRequestValidator.ValidateModel(request); if (validate.IsValid) { response = await _languageAppService.AddOrChange(request); } else { response.SetFail(validate.Errors.Select(p => p.ToString())); } return(Json(response)); } catch (Exception e) { _logger.LogError(e, Common.Common.GetMethodName(), request); throw; } }