Beispiel #1
0
        public async Task CreateCustomer(Customer customer)
        {
            await VerifyCustomerNameIsUnique(customer);

            _dbContext.Customers.Add(customer);

            await _dbContext.SaveChangesAsync();
        }
Beispiel #2
0
        public async Task CreateProduct(Product product)
        {
            await VerifyProductNameIsUnique(product);

            _dbContext.Products.Add(product);

            await _dbContext.SaveChangesAsync();
        }
Beispiel #3
0
        public async Task <Unit> Handle(CreateOrderV1Command request, CancellationToken cancellationToken)
        {
            await VerifyCustomerExists(request.Order.CustomerID);

            _dbContext.Orders.Add(request.Order);

            await _dbContext.SaveChangesAsync();

            return(Unit.Value);
        }
Beispiel #4
0
        public async Task <Unit> Handle(CreateProductV1Command request, CancellationToken cancellationToken)
        {
            await VerifyProductNameIsUnique(request.Product.Name);

            _dbContext.Products.Add(request.Product);

            await _dbContext.SaveChangesAsync();

            return(Unit.Value);
        }
Beispiel #5
0
        public async Task <Unit> Handle(UpdateCustomerV1Command request, CancellationToken cancellationToken)
        {
            await VerifyCustomerExists(request.Customer.ID);

            await VerifyCustomerNameIsUnique(request.Customer.ID, request.Customer.FirstName, request.Customer.LastName);

            _dbContext.Update(request.Customer);

            await _dbContext.SaveChangesAsync();

            return(Unit.Value);
        }
Beispiel #6
0
        public async Task <Unit> Handle(UpdateOrderV1Command request, CancellationToken cancellationToken)
        {
            await VerifyOrderExists(request.Order.ID);

            await VerifyOrderHasNotShipped(request.Order.ID);

            _dbContext.Update(request.Order);

            await _dbContext.SaveChangesAsync();

            return(Unit.Value);
        }
Beispiel #7
0
        public async Task CreateOrder(Order order)
        {
            await VerifyCustomerExists(order.CustomerID);

            _dbContext.Orders.Add(order);

            await _dbContext.SaveChangesAsync();
        }
Beispiel #8
0
        public async Task <Unit> Handle(DeleteProductV1Command request, CancellationToken cancellationToken)
        {
            await VerifyProductExists(request.ProductID);

            await VerifyProductHasNoOrders(request.ProductID);

            var product = await _dbContext.Products.FindAsync(request.ProductID);

            _dbContext.Products.Remove(product);

            await _dbContext.SaveChangesAsync();

            return(Unit.Value);
        }
Beispiel #9
0
        public async Task <Unit> Handle(DeleteCustomerV1Command request, CancellationToken cancellationToken)
        {
            await VerifyCustomerExists(request.CustomerID);

            await VerifyCustomerHasNoOrders(request.CustomerID);

            var customer = await _dbContext.Customers.FindAsync(request.CustomerID);

            _dbContext.Customers.Remove(customer);

            await _dbContext.SaveChangesAsync();

            return(Unit.Value);
        }
Beispiel #10
0
        public async Task <Unit> Handle(CreateOrderItemV1Command request, CancellationToken cancellationToken)
        {
            await VerifyOrderExists(request.OrderItem.OrderID);

            await VerifyOrderHasNotShipped(request.OrderItem.OrderID);

            await VerifyProductExists(request.OrderItem.ProductID);

            await VerifyOrderItemProductIsUnique(request.OrderItem);

            _dbContext.OrderItems.Add(request.OrderItem);

            await _dbContext.SaveChangesAsync();

            return(Unit.Value);
        }
Beispiel #11
0
        public async Task <Unit> Handle(DeleteOrderItemV1Command request, CancellationToken cancellationToken)
        {
            await VerifyOrderItemExists(request.OrderItemID);

            var orderItem = await _dbContext.OrderItems.FindAsync(request.OrderItemID);

            await VerifyOrderExists(orderItem.OrderID);

            await VerifyOrderHasNotShipped(orderItem.OrderID);

            _dbContext.OrderItems.Remove(orderItem);

            await _dbContext.SaveChangesAsync();

            return(Unit.Value);
        }
Beispiel #12
0
 public Task SaveChanges() => _dbContext.SaveChangesAsync();