Example #1
0
        public async Task Handle(OrderUpdatedV1Notification notification, CancellationToken cancellationToken)
        {
            var order = await _dbContext.Orders.SingleOrDefaultAsync(i => i.ID == notification.CustomerID, cancellationToken);

            if (order != null)
            {
                _dbContext.Orders.Remove(order);

                await _dbContext.SaveChangesAsync(cancellationToken);
            }

            order = new Order
            {
                CustomerID  = notification.CustomerID,
                ID          = notification.ID,
                OrderDate   = notification.OrderDate,
                OrderStatus = notification.OrderStatus,
                OrderItems  = notification.OrderItems.Select(i => new OrderItem
                {
                    ID        = i.ID,
                    OrderID   = i.OrderID,
                    ProductID = i.ProductID,
                    Quantity  = i.Quantity
                }).ToList()
            };

            await PriceOrder(order, cancellationToken);

            _dbContext.Orders.Add(order);

            await _dbContext.SaveChangesAsync(cancellationToken);
        }
Example #2
0
        public async Task Handle(CustomerDeletedV1Notification notification, CancellationToken cancellationToken)
        {
            var customer = await _dbContext.Customers.SingleOrDefaultAsync(i => i.ID == notification.ID, cancellationToken);

            if (customer == null)
            {
                return;
            }

            _dbContext.Customers.Remove(customer);

            await _dbContext.SaveChangesAsync(cancellationToken);
        }
Example #3
0
        public async Task Handle(ProductDeletedV1Notification notification, CancellationToken cancellationToken)
        {
            var product = await _dbContext.Products.SingleOrDefaultAsync(i => i.ID == notification.ID, cancellationToken);

            if (product == null)
            {
                return;
            }

            _dbContext.Products.Remove(product);

            await _dbContext.SaveChangesAsync(cancellationToken);
        }
Example #4
0
        public async Task Handle(CustomerCreatedV1Notification notification, CancellationToken cancellationToken)
        {
            var customer = await _dbContext.Customers.SingleOrDefaultAsync(i => i.ID == notification.ID, cancellationToken);

            if (customer != null)
            {
                return;
            }

            _dbContext.Customers.Add(new Customer
            {
                ID        = notification.ID,
                FirstName = notification.FirstName,
                LastName  = notification.LastName
            });

            await _dbContext.SaveChangesAsync(cancellationToken);
        }
Example #5
0
        public async Task Handle(CustomerUpdatedV1Notification notification, CancellationToken cancellationToken)
        {
            var customer = await _dbContext.Customers.SingleOrDefaultAsync(i => i.ID == notification.ID, cancellationToken);

            if (customer == null)
            {
                customer = new Customer {
                    ID = customer.ID
                };

                _dbContext.Customers.Add(customer);
            }

            customer.FirstName = notification.FirstName;
            customer.LastName  = notification.LastName;

            await _dbContext.SaveChangesAsync(cancellationToken);
        }
Example #6
0
        public async Task Handle(OrderCreatedV1Notification notification, CancellationToken cancellationToken)
        {
            var order = await _dbContext.Orders.SingleOrDefaultAsync(i => i.ID == notification.CustomerID, cancellationToken);

            if (order != null)
            {
                return;
            }

            _dbContext.Orders.Add(new Order
            {
                CustomerID  = notification.CustomerID,
                ID          = notification.ID,
                OrderDate   = notification.OrderDate,
                OrderStatus = notification.OrderStatus
            });

            await _dbContext.SaveChangesAsync(cancellationToken);
        }
Example #7
0
        public async Task Handle(ProductUpdatedV1Notification notification, CancellationToken cancellationToken)
        {
            var product = await _dbContext.Products.SingleOrDefaultAsync(i => i.ID == notification.ID, cancellationToken);

            if (product == null)
            {
                product = new Product {
                    ID = product.ID
                };

                _dbContext.Products.Add(product);
            }

            product.Category    = notification.Category;
            product.Description = notification.Description;
            product.Name        = notification.Name;
            product.Price       = notification.Price;

            await _dbContext.SaveChangesAsync(cancellationToken);
        }
Example #8
0
        public async Task Handle(ProductCreatedV1Notification notification, CancellationToken cancellationToken)
        {
            var product = await _dbContext.Products.SingleOrDefaultAsync(i => i.ID == notification.ID, cancellationToken);

            if (product != null)
            {
                return;
            }

            _dbContext.Products.Add(new Product
            {
                ID          = notification.ID,
                Category    = notification.Category,
                Description = notification.Description,
                Name        = notification.Name,
                Price       = notification.Price
            });

            await _dbContext.SaveChangesAsync(cancellationToken);
        }