Example #1
0
        public async Task <Unit> Handle(DeleteCustomerCommand request, CancellationToken cancellationToken)
        {
            var entity = await _context.Customers.FindAsync(request.Id);

            Guard.Against.NullCustomer(request.Id, entity);

            _context.Customers.Remove(entity);
            await _context.SaveChangesAsync(cancellationToken);

            return(Unit.Value);
        }
Example #2
0
        public async Task <Unit> Handle(UpdateCustomerCommand request, CancellationToken cancellationToken)
        {
            var entity = await _context.Customers.FindAsync(request.Id);

            Guard.Against.NullCustomer(request.Id, entity);

            entity.Active       = request.Active;
            entity.Address      = request.Address;
            entity.ContactData  = request.ContactData;
            entity.CustomerType = request.CustomerType;
            entity.Person       = request.Person;
            await _context.SaveChangesAsync(cancellationToken);

            return(Unit.Value);
        }
Example #3
0
        public async Task <int> Handle(CreateCustomerCommand request, CancellationToken cancellationToken)
        {
            var entity = new Customer
            {
                Active       = request.Active,
                Address      = request.Address,
                ContactData  = request.ContactData,
                CustomerType = request.CustomerType,
                Person       = request.Person
            };

            _context.Customers.Add(entity);
            await _context.SaveChangesAsync(cancellationToken);

            return(entity.Id);
        }