public async Task <ContractV1> UpdateContractAsync(string correlationId, ContractV1 contract) { var oldContract = await _persistence.GetByIdAsync(correlationId, contract.Id); if (oldContract != null) { contract.Customer.Id = oldContract.Customer.Id; if (string.IsNullOrEmpty(contract.Customer.Id)) { contract.Customer.Id = (await CreateCustomerAsync(correlationId, contract.Customer))?.Id; } else { await _customersConnector.UpdateCustomerAsync(correlationId, ToPublic(contract.Customer)); } return(await _persistence.UpdateAsync(correlationId, contract)); } throw new NotFoundException(correlationId, "CONTRACT_NOT_FOUND", string.Format($"Contract {contract.Id} was not found")); }
public async Task TestCrudOperationsAsync() { // Create items await TestCreateContractsAsync(); // Get all contracts var page = await _persistence.GetPageByFilterAsync( null, new FilterParams(), new PagingParams(), new SortParams() ); Assert.NotNull(page); Assert.Equal(3, page.Data.Count); var contract1 = page.Data[0]; // Update the contract contract1.Number = "ABC"; var contract = await _persistence.UpdateAsync(null, contract1); Assert.NotNull(contract); Assert.Equal(contract1.Id, contract.Id); Assert.Equal("ABC", contract.Number); // Delete the contract contract = await _persistence.DeleteByIdAsync(null, contract1.Id); Assert.NotNull(contract); Assert.Equal(contract1.Id, contract.Id); // Try to get deleted contract contract = await _persistence.GetByIdAsync(null, contract1.Id); Assert.Null(contract); }