Example #1
0
        public AddOrderResult Execute(AddOrderRequest request)
        {
            var result = new AddOrderResult();

            var customer = _context.Customers.Find(request.CustomerId);
            var product  = _context.Products.First(x => x.PartNumber == request.PartNumber);


            if (product.Available(request.Quantity) || product.CanFulfillBackOrder(request.Quantity))
            {
                result.ExpectedShipDate = DateTime.Now.AddDays(15);
            }
            else
            {
                result.ExpectedShipDate = DateTime.Now.AddDays(60);
            }


            _context.Orders.Add(new Order
            {
                Customer = customer,
                Product  = product,
                Quantity = request.Quantity
            });

            _context.SaveChanges();

            return(result);
        }
        public RefundCustomerResult Handle(RefundCustomerRequest request)
        {
            var customer = _context.Customers.Find(request.CustomerId);

            customer.CreditAccount(request.Amount);

            _context.SaveChanges();

            return(new RefundCustomerResult
            {
                CurrentAccountBalance = customer.AccountBalance,
                RefundAmount = request.Amount
            });
        }
        public AddProductResult Execute(AddProductRequest request)
        {
            var product = new Product
            {
                PartNumber = request.PartNumber,
                Price      = request.Price
            };

            _context.Products.Add(product);

            _context.SaveChanges();

            return(new AddProductResult
            {
                Message = $"Part Number {request.PartNumber} added with Product Id of {product.Id}",
                ProductId = product.Id
            });
        }