public void UpdateProductQuantity(IEnumerable <UpdatedProductSnapshot> productSnapshotDtos)
        {
            var changedProducts = GetBaseProductByItsSnapshot(productSnapshotDtos);

            if (changedProducts.Any())
            {
                foreach (var product in changedProducts)
                {
                    var numberofSoldProduct = productSnapshotDtos
                                              .SingleOrDefault(f => f.ProductNumber == product.ProductNumber).Amount;

                    product.UpdateQuantity(product.Quantity - numberofSoldProduct);
                }

                context.SaveChanges();
            }
        }
        public void UpdateCustomerEmotion(CustomerModel customer, CreateTransactionCommand command)
        {
            customer.LastestCustomerEmotion = command.CustomerEmotion;
            customer.EmotionProbability     = command.CustomerEmotionProbability;

            context.Entry <CustomerModel>(customer).State = System.Data.Entity.EntityState.Modified;

            context.SaveChanges();
        }
        public void Handle(DeleteProductCommand command)
        {
            var matchedProduct = context.Set <BaseProduct>()
                                 .FirstOrDefault(x => x.Id == command.Id);

            if (matchedProduct == null)
            {
                throw new NullReferenceException();
            }

            context.Set <BaseProduct>().Remove(matchedProduct);

            context.SaveChanges();
        }
Ejemplo n.º 4
0
        public string Handle(EditCustomerCommand command)
        {
            var existingCustomer = context.Set <CustomerBase>()
                                   .FirstOrDefault(x => x.CustomerId == command.CustomerId);

            if (existingCustomer == null)
            {
                throw new CustomerNotFoundException(command.CustomerId);
            }

            existingCustomer.Update(mapper.Map <Model.Customer.UpdatedCustomer>(command));

            context.SaveChanges();

            return(existingCustomer.CustomerId);
        }
Ejemplo n.º 5
0
        public Guid Handle(UpdateTransactionCommand command)
        {
            var existingtransaction = context.Set <Transaction>()
                                      .FirstOrDefault(x => x.TransactionNumber == command.TransactionNumber);

            if (existingtransaction == null)
            {
                throw new TransactionIsNotExistException(command.TransactionNumber);
            }

            existingtransaction.Update(mapper.Map <UpdatedTransaction>(command));

            UpdateProduct(existingtransaction, command);

            context.SaveChanges();

            return(existingtransaction.Id);
        }
Ejemplo n.º 6
0
        public string Handle(DeleteTransactionCommand command)
        {
            var existingTransaction = context.Set <Transaction>()
                                      .Include(x => x.ProductSnapshot)
                                      .FirstOrDefault(x => x.TransactionNumber == command.TransactionId);

            if (existingTransaction == null)
            {
                throw new TransactionIsNotExistException(command.TransactionId);
            }

            productUpdater.DeleteExistingProductSnapshot(existingTransaction.Id);

            context.Set <Transaction>().Remove(existingTransaction);

            context.SaveChanges();

            return(command.TransactionId);
        }
Ejemplo n.º 7
0
        public string Handle(CreateCustomerCommand command)
        {
            var existingCustomer = context.Set <CustomerModel>()
                                   .AsNoTracking()
                                   .FirstOrDefault(x => x.CustomerId == command.CustomerId);

            if (existingCustomer != null)
            {
                throw new DuplicateCustomerException(command.CustomerId);
            }

            var newCustomer = mapper.Map <CustomerModel>(command);

            context.Set <CustomerModel>().Add(newCustomer);

            context.SaveChanges();

            return(newCustomer.CustomerId);
        }
Ejemplo n.º 8
0
        public string Handle(EditProductCommnand commnand)
        {
            var existingProduct = context.Set <BaseProduct>()
                                  .SingleOrDefault(x => x.ProductNumber == commnand.ProductNumber);

            if (existingProduct == null)
            {
                throw new NullReferenceException($"The product with ID {commnand.ProductNumber} does not exist.");
            }

            existingProduct.Update(
                commnand.Name,
                commnand.Price,
                commnand.Quantity,
                commnand.ExpiryDate,
                commnand.ManufacturingDate);

            context.SaveChanges();

            return(existingProduct.ProductNumber);
        }