public async Task GivenOrdersExist(Table table) { foreach (var ordersTableItem in table.CreateSet <OrdersTable>()) { int?organisationAddressId = _context.GetAddressIdByPostcode(ordersTableItem.OrganisationAddressPostcode); int?organisationContactId = _context.GetContactIdByEmail(ordersTableItem.OrganisationContactEmail); int?supplierAddressId = _context.GetAddressIdByPostcode(ordersTableItem.SupplierAddressPostcode); int?supplierContactId = _context.GetContactIdByEmail(ordersTableItem.SupplierContactEmail); DateTime?commencementDate = null; if (ordersTableItem.CommencementDate != DateTime.MinValue) { commencementDate = ordersTableItem.CommencementDate; } var order = OrderEntityBuilder .Create() .WithOrderId(ordersTableItem.OrderId) .WithDescription(ordersTableItem.Description) .WithOrganisationId(ordersTableItem.OrganisationId) .WithOrganisationName(ordersTableItem.OrganisationName) .WithOrganisationOdsCode(ordersTableItem.OrganisationOdsCode) .WithOrganisationAddressId(organisationAddressId) .WithOrganisationBillingAddressId(ordersTableItem.OrganisationBillingAddressId) .WithOrganisationContactId(organisationContactId) .WithOrderStatusId(ordersTableItem.OrderStatusId) .WithDateCreated(ordersTableItem.Created != DateTime.MinValue ? ordersTableItem.Created : DateTime.UtcNow) .WithLastUpdatedBy(ordersTableItem.LastUpdatedBy) .WithLastUpdatedName(ordersTableItem.LastUpdatedByName) .WithLastUpdated(ordersTableItem.LastUpdated != DateTime.MinValue ? ordersTableItem.LastUpdated : DateTime.UtcNow) .WithServiceRecipientsViewed(ordersTableItem.ServiceRecipientsViewed) .WithCatalogueSolutionsViewed(ordersTableItem.CatalogueSolutionsViewed) .WithSupplierId(ordersTableItem.SupplierId) .WithSupplierName(ordersTableItem.SupplierName) .WithSupplierAddressId(supplierAddressId) .WithSupplierContactId(supplierContactId) .WithCommencementDate(commencementDate) .Build(); await order.InsertAsync(_settings.ConnectionString); } }
public async Task GivenOrdersExist(Table table) { foreach (var ordersTableItem in table.CreateSet <OrdersTable>()) { DateTime?commencementDate = null; if (ordersTableItem.CommencementDate != DateTime.MinValue) { commencementDate = ordersTableItem.CommencementDate; } var now = DateTime.UtcNow; var orderId = ordersTableItem.OrderId; var order = OrderEntityBuilder .Create() .WithOrderId(orderId) .WithDescription(ordersTableItem.Description) .WithOrganisationId(ordersTableItem.OrderingPartyId) .WithOrganisationContactId(ordersTableItem.OrderingPartyContactId) .WithOrderStatus(ordersTableItem.OrderStatus) .WithDateCreated(ordersTableItem.Created != DateTime.MinValue ? ordersTableItem.Created : now) .WithLastUpdatedBy(ordersTableItem.LastUpdatedBy) .WithLastUpdatedName(ordersTableItem.LastUpdatedByName) .WithLastUpdated(ordersTableItem.LastUpdated != DateTime.MinValue ? ordersTableItem.LastUpdated : now) .WithFundingSourceOnlyGms(ordersTableItem.FundingSourceOnlyGms) .WithSupplierId(ordersTableItem.SupplierId) .WithSupplierContactId(ordersTableItem.SupplierContactId) .WithCommencementDate(commencementDate) .WithIsDeleted(ordersTableItem.IsDeleted) .WithDateCompleted(ordersTableItem.Completed) .Build(); await order.InsertAsync(settings.OrderingDbAdminConnectionString); orderContext.OrderReferenceList.Add(orderId, order); } }