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); }
public async Task <Guid> HandleAsync(AddAddressToOrganisation message) { authorization.EnsureOrganisationAccess(message.OrganisationId); var addresstype = ValueObjectInitializer.GetAddressType(message.TypeOfAddress); if (await db.Organisations.FirstOrDefaultAsync(o => o.Id == message.OrganisationId) == null) { throw new ArgumentException(string.Format("Could not find an organisation with id {0}", message.OrganisationId)); } var organisation = await db.Organisations.SingleAsync(o => o.Id == message.OrganisationId); if (await db.Countries.FirstOrDefaultAsync(c => c.Id == message.Address.CountryId) == null) { throw new ArgumentException(string.Format("Could not find country with id {0}", message.Address.CountryId)); } var country = await db.Countries.SingleAsync(c => c.Id == message.Address.CountryId); message.Address.CountryName = country.Name; var address = ValueObjectInitializer.CreateAddress(message.Address, country); if (addresstype.Equals(AddressType.SchemeAddress)) { if (message.AddressId.HasValue) { var findAddress = await db.Addresses.SingleAsync(a => a.Id == message.AddressId.Value); findAddress.Overwrite(address); address = findAddress; } else { db.Addresses.Add(address); } } else { organisation.AddOrUpdateAddress(addresstype, address); } await db.SaveChangesAsync(); return(GetAddressId(addresstype, organisation, address)); }
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); }
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); }
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); }
public async Task <Guid> HandleAsync(CreateOrganisationAdmin message) { authorization.EnsureCanAccessInternalArea(); authorization.EnsureUserInRole(Roles.InternalAdmin); Organisation organisation = null; switch (message.OrganisationType) { case Core.Organisations.OrganisationType.Partnership: organisation = Organisation.CreatePartnership(message.BusinessName); break; case Core.Organisations.OrganisationType.RegisteredCompany: organisation = Organisation.CreateRegisteredCompany(message.BusinessName, message.RegistrationNumber, message.TradingName); break; case Core.Organisations.OrganisationType.SoleTraderOrIndividual: organisation = Organisation.CreateSoleTrader(message.BusinessName, message.TradingName); break; default: break; } if (organisation == null) { throw new NotImplementedException("This organisation type hasn't been implented"); } Country country = await db.Countries.SingleAsync(c => c.Id == message.Address.CountryId); Address address = ValueObjectInitializer.CreateAddress(message.Address, country); await dataAccess.Add <Address>(address); organisation.AddOrUpdateAddress(AddressType.RegisteredOrPPBAddress, address); Guid id = await dataAccess.Add <Organisation>(organisation); return(id); }
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); }
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); }
private async Task <Address> GetAddress(AddAddressBookEntry message) { var country = await context.Countries.SingleAsync(c => c.Id == message.Address.CountryId); return(ValueObjectInitializer.CreateAddress(message.Address, country.Name)); }