public async Task <Unit> Handle(UpdateIntermediaryCommand request, CancellationToken cancellationToken)
        {
            var entity = await _context.Intermediaries
                         .SingleAsync(c => c.IntermediaryId == request.Id, cancellationToken);

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

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

            _context.Intermediaries.Update(entity);

            await _context.SaveChangesAsync(cancellationToken);

            return(Unit.Value);
        }
        public async Task <Unit> Handle(CreateIntermediaryCommand request, CancellationToken cancellationToken)
        {
            var entity = new Intermediary
            {
                IntermediaryId = request.Id,
                Name           = request.Name,
                Address        = request.Address,
                City           = request.City,
                ContactName    = request.ContactName,
                ContactTitle   = request.ContactTitle,
                Country        = request.Country,
                Fax            = request.Fax,
                Phone          = request.Phone,
                PostalCode     = request.PostalCode
            };

            _context.Intermediaries.Add(entity);

            await _context.SaveChangesAsync(cancellationToken);

            return(Unit.Value);
        }
        public async Task <Unit> Handle(DeleteIntermediaryCommand request, CancellationToken cancellationToken)
        {
            var entity = await _context.Intermediaries
                         .FindAsync(request.Id);

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

            var hasFiles = false; //_context.Files.Any(o => o.IntermediaryId == entity.IntermediaryId);

            if (hasFiles)
            {
                throw new DeleteFailureException(nameof(Intermediary), request.Id, "There are existing files associated with this Intermediary.");
            }

            _context.Intermediaries.Remove(entity);

            await _context.SaveChangesAsync(cancellationToken);

            return(Unit.Value);
        }