Esempio n. 1
0
        public async Task <Guid> HandleAsync(AddContactPerson message)
        {
            authorization.EnsureOrganisationAccess(message.OrganisationId);

            var contactPerson = ValueObjectInitializer.CreateContact(message.ContactPerson);

            Guid id;

            if (message.ContactId.HasValue)
            {
                var contact = await dataAccess.GetById <Contact>(message.ContactId.Value);

                contact.Overwrite(contactPerson);

                id = contact.Id;
            }
            else
            {
                id = await dataAccess.Add <Contact>(contactPerson);
            }

            await db.SaveChangesAsync();

            return(id);
        }
Esempio n. 2
0
        public async Task <Unit> HandleAsync(SetExporterDetails message)
        {
            var exporter = await repository.GetByNotificationId(message.NotificationId);

            var contact  = ValueObjectInitializer.CreateContact(message.Exporter.Contact);
            var business = ValueObjectInitializer.CreateBusiness(message.Exporter.Business);

            exporter.UpdateContactAndBusiness(contact, business);

            await context.SaveChangesAsync();

            return(Unit.Value);
        }
        public async Task <bool> HandleAsync(AddAddressBookEntry message)
        {
            var addressBook = await addressBookRepository.GetAddressBookForUser(userContext.UserId, message.Type);

            var address = await GetAddress(message);

            var business = GetBusiness(message);
            var contact  = ValueObjectInitializer.CreateContact(message.Contact);

            addressBook.Add(new AddressBookRecord(address, business, contact));

            await addressBookRepository.Update(addressBook);

            return(true);
        }
        public async Task <Guid> HandleAsync(AddCarrierToNotification command)
        {
            var carriers = await repository.GetByNotificationId(command.NotificationId);

            var country = await countryRepository.GetById(command.Address.CountryId.Value);

            var business = ValueObjectInitializer.CreateBusiness(command.Business);
            var address  = ValueObjectInitializer.CreateAddress(command.Address, country.Name);
            var contact  = ValueObjectInitializer.CreateContact(command.Contact);
            var carrier  = carriers.AddCarrier(business, address, contact);

            await context.SaveChangesAsync();

            return(carrier.Id);
        }
Esempio n. 5
0
        public async Task <bool> HandleAsync(AddNewAddressBookEntry message)
        {
            var addressBook = await addressBookRepository.GetAddressBookForUser(userContext.UserId, message.Type);

            var country = await context.Countries.SingleAsync(c => c.Id == message.Address.CountryId);

            var address  = ValueObjectInitializer.CreateAddress(message.Address, country.Name);
            var business = ValueObjectInitializer.CreateBusiness(message.Business);
            var contact  = ValueObjectInitializer.CreateContact(message.Contact);

            addressBook.Add(new AddressBookRecord(address, business, contact));

            await addressBookRepository.Update(addressBook);

            return(true);
        }
Esempio n. 6
0
        public async Task <Guid> HandleAsync(AddFacilityToNotification message)
        {
            var country = await context.Countries.SingleAsync(c => c.Id == message.Address.CountryId);

            var business = ValueObjectInitializer.CreateBusiness(message.Business);
            var address  = ValueObjectInitializer.CreateAddress(message.Address, country.Name);
            var contact  = ValueObjectInitializer.CreateContact(message.Contact);

            var facilityCollection = await facilityRepository.GetByNotificationId(message.NotificationId);

            var facility = facilityCollection.AddFacility(business, address, contact);

            await context.SaveChangesAsync();

            return(facility.Id);
        }
Esempio n. 7
0
        public async Task <Guid> HandleAsync(AddProducerToNotification command)
        {
            var country = await countryRepository.GetById(command.Address.CountryId.Value);

            var address  = ValueObjectInitializer.CreateAddress(command.Address, country.Name);
            var contact  = ValueObjectInitializer.CreateContact(command.Contact);
            var business = ProducerBusiness.CreateProducerBusiness(command.Business.Name, command.Business.BusinessType,
                                                                   command.Business.RegistrationNumber, command.Business.OtherDescription);

            var producers = await repository.GetByNotificationId(command.NotificationId);

            var producer = producers.AddProducer(business, address, contact);

            await context.SaveChangesAsync();

            return(producer.Id);
        }
Esempio n. 8
0
        public async Task <Guid> HandleAsync(UpdateCarrierForNotification message)
        {
            var country = await context.Countries.SingleAsync(c => c.Id == message.Address.CountryId);

            var carriers = await repository.GetByNotificationId(message.NotificationId);

            var business = ValueObjectInitializer.CreateBusiness(message.Business);
            var address  = ValueObjectInitializer.CreateAddress(message.Address, country.Name);
            var contact  = ValueObjectInitializer.CreateContact(message.Contact);

            var carrier = carriers.GetCarrier(message.CarrierId);

            carrier.Address  = address;
            carrier.Business = business;
            carrier.Contact  = contact;

            await context.SaveChangesAsync();

            return(carrier.Id);
        }
        public async Task <Guid> HandleAsync(UpdateProducerForNotification message)
        {
            var country = await countryRepository.GetById(message.Address.CountryId.Value);

            var producers = await repository.GetByNotificationId(message.NotificationId);

            var business = ProducerBusiness.CreateProducerBusiness(message.Business.Name,
                                                                   message.Business.BusinessType,
                                                                   message.Business.RegistrationNumber,
                                                                   message.Business.OtherDescription);
            var address = ValueObjectInitializer.CreateAddress(message.Address, country.Name);
            var contact = ValueObjectInitializer.CreateContact(message.Contact);

            var producer = producers.GetProducer(message.ProducerId);

            producer.Address  = address;
            producer.Business = business;
            producer.Contact  = contact;

            await context.SaveChangesAsync();

            return(producer.Id);
        }
Esempio n. 10
0
        public async Task <Guid> HandleAsync(SetImporterForNotification message)
        {
            var country = await context.Countries.SingleAsync(c => c.Id == message.Address.CountryId);

            var business = ValueObjectInitializer.CreateBusiness(message.Business);
            var address  = ValueObjectInitializer.CreateAddress(message.Address, country.Name);
            var contact  = ValueObjectInitializer.CreateContact(message.Contact);

            var importer = await repository.GetImporterOrDefaultByNotificationId(message.NotificationId);

            if (importer == null)
            {
                importer = new Importer(message.NotificationId, address, business, contact);
                repository.Add(importer);
            }
            else
            {
                importer.Update(address, business, contact);
            }

            await context.SaveChangesAsync();

            return(importer.Id);
        }