public async Task <Unit> Handle(DeleteCustomerCommand request, CancellationToken cancellationToken) { var customer = await _context.Customers.FindAsync(request.Id); if (customer == null) { throw new NotFoundException(nameof(Customer), request.Id); } _context.Customers.Remove(customer); await _context.SaveChangesAsync(cancellationToken); return(Unit.Value); }
public async Task <Customer> Handle(CreateCustomerCommand request, CancellationToken cancellationToken) { var customer = new Customer( request.FirstName, request.LastName, request.Dob ); _context.Add(customer); await _context.SaveChangesAsync(cancellationToken); return(customer); }
public async Task <Customer> Handle(UpdateCustomerCommand request, CancellationToken cancellationToken) { var customer = await _context.Customers.FindAsync(request.Id); if (customer == null) { throw new NotFoundException(nameof(Customer), request.Id); } customer.FirstName = request.FirstName; customer.LastName = request.LastName; customer.Dob = request.Dob; await _context.SaveChangesAsync(cancellationToken); return(customer); }