Exemple #1
0
        public async Task DeleteAsync(int id)
        {
            try
            {
                var invoice = await _invoiceDataProvider.GetByOrderIdAsync(id);

                var message = $"Order {id} cannot be deleted because invoice {invoice.Id} is attached to it.";
                _logger.LogError(message);
                throw new InvalidOperationException(message);
            }
            catch (EntityNotFoundException)
            {
                var pageQuery = new QuerySet();
                pageQuery.Page.Size = 1;

                var depositInvoices = await _depositInvoiceDataProvider.GetAllByOrderIdAsync(id, pageQuery);

                if (depositInvoices.Count > 0)
                {
                    var message = $"Order {id} cannot be deleted because {depositInvoices.Count} deposit-invoices attached to it.";
                    _logger.LogError(message);
                    throw new InvalidOperationException(message);
                }

                var deposits = await _depositDataProvider.GetAllByOrderIdAsync(id, pageQuery);

                if (deposits.Count > 0)
                {
                    var message = $"Order {id} cannot be deleted because {deposits.Count} deposits are attached to it.";
                    _logger.LogError(message);
                    throw new InvalidOperationException(message);
                }

                // TODO reset ordered flag of offerlines on deletion instead of throwing an error?
                var offerlines = await _offerlineDataProvider.GetOrderedByOrderIdAsync(id, pageQuery);

                if (offerlines.Count > 0)
                {
                    var message = $"Order {id} cannot be deleted because {offerlines.Count} ordered offerlines are attached to it.";
                    _logger.LogError(message);
                    throw new InvalidOperationException(message);
                }

                try
                {
                    var order = await _orderDataProvider.GetByIdAsync(id);

                    await _graphApiService.DeleteEventForPlanningAsync(order);

                    await _orderDataProvider.DeleteByIdAsync(id);
                }
                catch (EntityNotFoundException)
                {
                    // Order not found. Nothing should happen.
                }
            }
        }
Exemple #2
0
        public async Task <Paged <Deposit> > GetAllByOrderIdAsync(int orderId, QuerySet query)
        {
            if (query.Sort.Field == null)
            {
                query.Sort.Order = SortQuery.ORDER_DESC;
                query.Sort.Field = "payment-date";
            }

            return(await _depositDataProvider.GetAllByOrderIdAsync(orderId, query));
        }
Exemple #3
0
        public async Task DeleteAsync(int id)
        {
            try
            {
                var invoice = await _invoiceDataProvider.GetByOrderIdAsync(id);

                var message = $"Order {id} cannot be deleted because invoice {invoice.Id} is attached to it.";
                _logger.LogError(message);
                throw new InvalidOperationException(message);
            }
            catch (EntityNotFoundException)
            {
                var pageQuery = new QuerySet();
                pageQuery.Page.Size = 1;

                var depositInvoices = await _depositInvoiceDataProvider.GetAllByOrderIdAsync(id, pageQuery);

                if (depositInvoices.Count > 0)
                {
                    var message = $"Order {id} cannot be deleted because {depositInvoices.Count} deposit-invoices attached to it.";
                    _logger.LogError(message);
                    throw new InvalidOperationException(message);
                }

                var deposits = await _depositDataProvider.GetAllByOrderIdAsync(id, pageQuery);

                if (deposits.Count > 0)
                {
                    var message = $"Order {id} cannot be deleted because {deposits.Count} deposits are attached to it.";
                    _logger.LogError(message);
                    throw new InvalidOperationException(message);
                }

                try
                {
                    var order = await _orderDataProvider.GetByIdAsync(id);

                    await _documentGenerationManager.DeleteOrderDocumentAsync(id);

                    await _documentGenerationManager.DeleteDeliveryNoteAsync(id);

                    await _documentGenerationManager.DeleteProductionTicketTemplateAsync(id);

                    await _documentGenerationManager.DeleteProductionTicketAsync(id);

                    await _orderDataProvider.DeleteByIdAsync(id);
                }
                catch (EntityNotFoundException)
                {
                    // Order not found. Nothing should happen.
                }
            }
        }