Beispiel #1
0
        public void UpdateOrder(ImportingOrderDto order)
        {
            var oldOrder = importingOrderRepository.GetBy(order.Id);

            oldOrder.ImportingTransactions = importingTransactionRepository.GetByImportingId(order.Id).ToList();

            /*Remove old quantity*/
            List <Product> productList = new List <Product>();

            foreach (var transaction in oldOrder.ImportingTransactions)
            {
                var product = productRepository.GetBy(transaction.ProductId);
                product.Quantity -= transaction.Quantity;
                productList.Add(product);
            }
            productRepository.UpdateQuantity(productList);

            /*Remove old transaction*/
            importingTransactionRepository.RemoveRange(oldOrder.ImportingTransactions);

            /*Add new quantity*/
            List <Product> newProductList = new List <Product>();

            foreach (var transaction in order.ImportingTransactions)
            {
                transaction.ImportingOrderId = order.Id;
                var product = productRepository.GetBy(transaction.ProductId);
                product.Quantity += transaction.Quantity;
                newProductList.Add(product);
            }
            productRepository.UpdateQuantity(newProductList);

            /*Add new transaction*/
            importingOrderRepository.Update(order.MappingImportingOrder());
        }
Beispiel #2
0
        public ImportingOrderDto UpdateImportingOrder(ImportingOrderDto orderDto)
        {
            var order = _mapper.Map <ImportingOrder>(orderDto);
            int res   = _orderRepo.Update(order);

            if (res <= 0)
            {
                return(null);
            }
            return(orderDto);
        }