public async Task <CustomerAddOrChangeResponse> AddOrChange(CustomerAddOrChangeRequest request) { CustomerAddOrChangeResponse response = new CustomerAddOrChangeResponse(); try { var userLogin = await _context.GetCurrentCustomer(); CommandResult result; if (string.IsNullOrEmpty(request.Id)) { long systemIdentity = await _commonService.GetNextId(typeof(Customer)); string code = Common.Common.GenerateCodeFromId(systemIdentity, 3); var command = request.ToCommand(_context.Ip, userLogin.Id, code); result = await _customerService.SendCommand(command); } else { var command = request.ToCommand(_context.Ip, userLogin.Id, request.Version); result = await _customerService.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] CustomerAddOrChangeRequest request) { try { CustomerAddOrChangeResponse response = new CustomerAddOrChangeResponse(); ValidationResult validate = CustomerAddRequestValidator.ValidateModel(request); if (validate.IsValid) { response = await _customerAppService.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; } }