Ejemplo n.º 1
0
        private void UpdateProduct(Transaction existingtransaction, UpdateTransactionCommand command)
        {
            if (productUpdater.ValidListOfProductResult(mapper.Map <IEnumerable <UpdatedProductSnapshot> >(command.ProductSnapshotDto)).IsValid)
            {
                productUpdater.RevertQuantiyOfBaseProduct(mapper.Map <IEnumerable <UpdatedProductSnapshot> >(existingtransaction.ProductSnapshot));

                productUpdater.DeleteExistingProductSnapshot(existingtransaction.Id);

                var productSnapshots = productUpdater.CreateNewListofProductSnapshot(mapper.Map <IEnumerable <UpdatedProductSnapshot> >(command.ProductSnapshotDto), existingtransaction.Id).ToList();
                foreach (var snapshot in productSnapshots)
                {
                    existingtransaction.ProductSnapshot.Add(snapshot);
                }

                productUpdater.UpdateProductQuantity(mapper.Map <IEnumerable <UpdatedProductSnapshot> >(command.ProductSnapshotDto));
            }
        }
Ejemplo n.º 2
0
        public string Handle(CreateTransactionCommand command)
        {
            var existingTransaction = context.Set <Transaction>()
                                      .FirstOrDefault(x => x.TransactionNumber == command.TransactionNumber);

            if (existingTransaction != null)
            {
                throw new DuplicateTransactionNumerException(command.TransactionNumber);
            }

            var transaction = mapper.Map <Transaction>(command);

            var customer = customerUpdater.GetCustomerByCustomerNumber(command.CustomerId);

            if (customer != null)
            {
                transaction.CustomerId = customer.Id;
                customerUpdater.UpdateCustomerEmotion(customer, command);
            }

            if (productUpdater.ValidListOfProductResult(mapper.Map <IEnumerable <UpdatedProductSnapshot> >(command.ProductSnapshotDto)).IsValid)
            {
                transaction.ProductSnapshot = productUpdater.CreateNewListofProductSnapshot(
                    mapper.Map <IEnumerable <UpdatedProductSnapshot> >(command.ProductSnapshotDto),
                    transaction.Id);

                context.Set <Transaction>().Add(transaction);

                context.SaveChangesAsync();

                //TODO: Move this function after implementing background jobs.
                productUpdater.UpdateProductQuantity(mapper.Map <IEnumerable <UpdatedProductSnapshot> >(command.ProductSnapshotDto));
            }

            return(transaction.TransactionNumber);
        }