public async Task <ManufacturerGetResponse> AddOrChange(ManufacturerManagementAddOrChangeRequest request) { ManufacturerGetResponse response = new ManufacturerGetResponse(); try { CommandResult result; if (request.Id == 0) { var command = request.ToCommand_Add(); result = await _manufacturerService.SendCommand(command); } else { var command = request.ToCommand_Change(); result = await _manufacturerService.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 static ManufacturerManagementAddCommand ToCommand_Add(this ManufacturerManagementAddOrChangeRequest request) { if (request == null) { return(null); } else { return new ManufacturerManagementAddCommand(SystemDefine.DefaultVersion) { Name = request.Name, Description = request.Description, Logo = request.Logo, CreatedDateUtc = Extensions.GetCurrentDateUtc() } }; }
public async Task <IActionResult> AddOrChange([FromBody] ManufacturerManagementAddOrChangeRequest request) { try { ManufacturerGetResponse response = new ManufacturerGetResponse(); ValidationResult validate = ManufacturerManagementAddRequestValidator.ValidateModel(request); if (validate.IsValid) { response = await _manufacturerAppService.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; } }