Пример #1
0
        public async Task HandleAsync(UpdateHeadOffice message, IRequestInfo requestInfo)
        {
            var business = await _repository.GetBusinessAsync(message.BusinessId);

            if (business is null)
            {
                _publisher.PublishEvent(new UpdateBusinessRejected(Codes.InvalidId, "A business with the id: " + message.BusinessId + "could not be found"), requestInfo);
                return;
            }

            try
            {
                business.GetOffice().Update(message.PostCode, message.AddressLine1, message.AddressLine2);
            }
            catch (VmsException e)
            {
                _publisher.PublishEvent(new UpdateBusinessRejected(e.Code, e.Message), requestInfo);
                return;
            }

            await _repository.UpdateAsync(business);

            _publisher.PublishEvent(new BusinessOfficeUpdated(), requestInfo);
            _logger.LogInformation("The business head office was updated successfully.");
        }
Пример #2
0
        public async Task HandleAsync(UpdateHeadContact message, IRequestInfo requestInfo)
        {
            var business = await _repository.GetBusinessAsync(message.BusinessId);

            if (business is null)
            {
                _publisher.PublishEvent(new UpdateBusinessRejected(Codes.InvalidId, "A business with the id: " + message.BusinessId + "could not be found"), requestInfo);
                return;
            }

            try
            {
                business.GetContact().Update(message.FirstName, message.SecondName, message.ContactNumber, message.Email);
            }
            catch (VmsException e)
            {
                _publisher.PublishEvent(new UpdateBusinessRejected(e.Code, e.Message), requestInfo);
                return;
            }

            await _repository.UpdateAsync(business);

            _publisher.PublishEvent(new BusinessContactUpdated(), requestInfo);
            _logger.LogInformation("The business contact was updated successfully.");
        }
Пример #3
0
        public async Task <BusinessDto> HandleAsync(GetBusiness query)
        {
            var domain = await _repository.GetBusinessAsync(query.Id);

            if (domain is null)
            {
                _logger.LogInformation("No business found for the id: " + query.Id);
                return(null);
            }

            return(new BusinessDto()
            {
                Id = domain.Id,
                Name = domain.Name,
                TradingName = domain.TradingName,
                WebAddress = domain.WebAddress?.ToString(),
                Code = domain.Code.ToString(),
                Contact = new HeadContactDto()
                {
                    ContactNumber = domain.GetContact()?.ContactNumber, Email = domain.GetContact()?.Email,
                    FirstName = domain.GetContact()?.FirstName, SecondName = domain.GetContact()?.SecondName
                },
                Office = new HeadOfficeDto()
                {
                    AddressLine1 = domain.GetOffice()?.AddressLine1, AddressLine2 = domain.GetOffice()?.AddressLine2,
                    PostCode = domain.GetOffice()?.PostCode
                }
            });
        }
Пример #4
0
        public async Task HandleAsync(UpdateBusinessDetails message, IRequestInfo requestInfo)
        {
            var business = await _repository.GetBusinessAsync(message.Id);
            if (business is null)
            {
                _publisher.PublishEvent(new UpdateBusinessRejected(Codes.InvalidId, "A business with the id: " + message.Id + "could not be found"), requestInfo);
                return;
            }

            try
            {
                business.Update(message.Name, message.TradingName, message.WebAddress);
            }
            catch (VmsException e)
            {
                _publisher.PublishEvent(new UpdateBusinessRejected(e.Code, e.Message), requestInfo);
                return;
            }

            await _repository.UpdateAsync(business);
            _publisher.PublishEvent(new BusinessDetailsUpdated(), requestInfo);
            _logger.LogInformation("The business was updated successfully.");
        }