예제 #1
0
        public async Task <ActionResult> Delete(long id)
        {
            try
            {
                var order = await context.Orders
                            .FindAsync(id);

                if (order == null)
                {
                    return(NotFound());
                }

                // Process line items
                await inventoryService.ProcessAdjustments(order.LineItems, AdjustmentType.Add, Constants.AdjustmentRemarks.OrderDeleted, QuantityType.Quantity);

                context.Remove(order);
                await context.SaveChangesAsync();

                return(StatusCode(StatusCodes.Status204NoContent));
            }
            catch (DbUpdateException e)
            {
                logger.LogError(e.Message);
                return(StatusCode(StatusCodes.Status500InternalServerError, "Order cannot be deleted at this moment. There might be other records using it as a reference (i.e. credit memo, delivery)."));
            }
            catch (Exception e)
            {
                logger.LogError(e.Message);
                return(StatusCode(StatusCodes.Status500InternalServerError));
            }
        }
예제 #2
0
        public async Task <ActionResult> Delete(long id)
        {
            try
            {
                var invoice = await context.Invoices
                              .Include(c => c.LineItems)
                              .SingleOrDefaultAsync(c => c.Id == id);

                if (invoice == null)
                {
                    return(NotFound());
                }

                // Process item quantities
                var orderIds       = invoice.LineItems.Where(a => a.OrderId != null).Select(a => a.OrderId.Value);
                var orderLineItems = context.OrderLineItems
                                     .Where(a => orderIds.Contains(a.OrderId));
                await inventoryService.ProcessAdjustments(orderLineItems, AdjustmentType.Add, Constants.AdjustmentRemarks.InvoiceCreated, QuantityType.StockQuantity);

                await orderService.ProcessInvoice(invoice.LineItems, false);

                context.Remove(invoice);

                await context.SaveChangesAsync();

                return(StatusCode(StatusCodes.Status204NoContent));
            }
            catch (Exception e)
            {
                logger.LogError(e.Message);
                return(StatusCode(StatusCodes.Status500InternalServerError));
            }
        }
예제 #3
0
        public async Task <ActionResult> Delete(long id)
        {
            try
            {
                var delivery = await context.Deliveries
                               .Include(c => c.LineItems)
                               .ThenInclude(lineItem => (lineItem as DeliveryLineItem).OrderLineItem)
                               .ThenInclude(orderLineItem => orderLineItem.Item)
                               .SingleOrDefaultAsync(c => c.Id == id);

                if (delivery == null)
                {
                    return(NotFound());
                }

                // Update the order line item for quantity delivered
                await orderService.ProcessDeliveries(delivery.LineItems, AdjustmentType.Deduct);

                context.Remove(delivery);
                await context.SaveChangesAsync();

                return(StatusCode(StatusCodes.Status204NoContent));
            }
            catch (Exception e)
            {
                logger.LogError(e.Message);
                return(StatusCode(StatusCodes.Status500InternalServerError));
            }
        }
        public async Task <ActionResult> Delete(long id)
        {
            try
            {
                var cashVoucher = await context.CashVouchers.SingleOrDefaultAsync(t => t.Id == id);

                if (cashVoucher == null)
                {
                    return(NotFound());
                }

                context.Remove(cashVoucher);
                await context.SaveChangesAsync();

                return(StatusCode(StatusCodes.Status204NoContent));
            }
            catch (Exception e)
            {
                logger.LogError(e.Message);
                return(StatusCode(StatusCodes.Status500InternalServerError));
            }
        }
        public async Task <ActionResult> Delete(long id)
        {
            try
            {
                var creditMemo = await context.CreditMemos
                                 .Include(c => c.LineItems)
                                 .ThenInclude(detail => (detail as CreditMemoLineItem).OrderLineItem)
                                 .ThenInclude(orderLineItem => orderLineItem.Item)
                                 .Include(c => c.LineItems)
                                 .ThenInclude(detail => (detail as CreditMemoLineItem).TransactionHistory)
                                 .AsNoTracking()
                                 .SingleOrDefaultAsync(c => c.Id == id);

                if (creditMemo == null)
                {
                    return(NotFound(id));
                }

                // Adjust inventory quantities
                var itemsToBeCleared = creditMemo.LineItems.Where(a => a.ReturnedToInventory);
                await inventoryService.ProcessAdjustments(itemsToBeCleared, AdjustmentType.Deduct, Constants.AdjustmentRemarks.CreditMemoDeleted, QuantityType.Both);

                // Update order line items for quantity returned
                await orderService.ProcessReturns(creditMemo.LineItems, AdjustmentType.Deduct);

                context.Remove(creditMemo);
                await context.SaveChangesAsync();

                return(StatusCode(StatusCodes.Status204NoContent));
            }
            catch (Exception e)
            {
                logger.LogError(e.Message);
                return(StatusCode(StatusCodes.Status500InternalServerError));
            }
        }
        public async Task <ActionResult> Delete(long id)
        {
            try
            {
                var salesQuote = await context
                                 .SalesQuotes
                                 .FindAsync(id);

                if (salesQuote == null)
                {
                    return(NotFound());
                }

                context.Remove(salesQuote);
                await context.SaveChangesAsync();

                return(StatusCode(StatusCodes.Status204NoContent));
            }
            catch (Exception e)
            {
                logger.LogError(e.Message);
                return(StatusCode(StatusCodes.Status500InternalServerError));
            }
        }