public async Task <Unit> Handle(UpdateFleetDriver_Command request, CancellationToken cancellationToken)
            {
                _context.Driver.Update(request.Driver);
                await _context.SaveChangesAsync(cancellationToken);

                return(Unit.Value);
            }
            public async Task <Unit> Handle(CreateFleetCustomer_Command request, CancellationToken cancellationToken)
            {
                var entity = _mapper.Map <Customer>(request.Customer);

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

                await _mediator.Publish(new FleetCustomerCreated { Id = entity.Id }, cancellationToken);

                return(Unit.Value);
            }
Esempio n. 3
0
        public async Task <Unit> Handle(DeleteFleetCustomerCommand request, CancellationToken cancellationToken)
        {
            var entity = await _context.Customer
                         .FindAsync(request.Id);

            if (entity == null)
            {
                throw new NotFoundException(nameof(Customer), request.Id);
            }

            //var hasOrders = _context.Orders.Any(o => o.CustomerId == entity.Id);
            //if (hasOrders)
            //{
            //    // TODO: Add functional test for this behaviour.
            //    throw new DeleteFailureException(nameof(Customer), request.Id, "There are existing orders associated with this customer.");
            //}

            _context.Customer.Remove(entity);

            await _context.SaveChangesAsync(cancellationToken);

            return(Unit.Value);
        }
Esempio n. 4
0
            public async Task <Unit> Handle(UpdateFleetCustomerCommand request, CancellationToken cancellationToken)
            {
                //var entity = await _context.Customer
                //    .SingleOrDefaultAsync(c => c.Id == request.Id, cancellationToken);

                //if (entity == null)
                //{
                //    throw new NotFoundException(nameof(Customer), request.Id);
                //}

                //entity.Address = request.Address;
                //entity.City = request.City;
                //entity.CompanyName = request.CompanyName;
                //entity.ContactName = request.ContactName;
                //entity.ContactTitle = request.ContactTitle;
                //entity.Country = request.Country;
                //entity.Fax = request.Fax;
                //entity.Phone = request.Phone;
                //entity.PostalCode = request.PostalCode;

                await _context.SaveChangesAsync(cancellationToken);

                return(Unit.Value);
            }