コード例 #1
0
        public async Task <Paged <Building> > GetAllByCustomerIdAsync(int customerId, QuerySet query)
        {
            if (query.Sort.Field == null)
            {
                query.Sort.Field = "name";
            }

            return(await _buildingDataProvider.GetAllByCustomerIdAsync(customerId, query));
        }
コード例 #2
0
ファイル: CustomerManager.cs プロジェクト: rollvolet/crm-api
        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);
        }