public async Task <Paged <Contact> > GetAllByCustomerIdAsync(int customerId, QuerySet query) { if (query.Sort.Field == null) { query.Sort.Field = "name"; } return(await _contactDataProvider.GetAllByCustomerIdAsync(customerId, query)); }
public async Task DeleteAsync(int id) { var query = new QuerySet(); query.Page.Size = 1; var requests = await _requestDataProvider.GetAllByCustomerIdAsync(id, query); if (requests.Count > 0) { _logger.LogError($"Customer {id} cannot be deleted because requests are still attached to it."); throw new InvalidOperationException($"Customer {id} cannot be deleted because requests are still attached to it."); } var invoices = await _invoiceDataProvider.GetAllByCustomerIdAsync(id, query); if (invoices.Count > 0) { _logger.LogError($"Customer {id} cannot be deleted because invoices are still attached to it."); throw new InvalidOperationException($"Customer {id} cannot be deleted because invoices are still attached to it."); } var contacts = await _contactDataProvider.GetAllByCustomerIdAsync(id, query); if (contacts.Count > 0) { _logger.LogError($"Customer {id} cannot be deleted because contacts are still attached to it."); throw new InvalidOperationException($"Customer {id} cannot be deleted because contacts are still attached to it."); } var buildings = await _buildingDataProvider.GetAllByCustomerIdAsync(id, query); if (buildings.Count > 0) { _logger.LogError($"Customer {id} cannot be deleted because buildings are still attached to it."); throw new InvalidOperationException($"Customer {id} cannot be deleted because buildings are still attached to it."); } await _customerDataProvider.DeleteByNumberAsync(id); }