예제 #1
0
        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 <bool> HandleAsync(UpdateOrganisationDetails message)
        {
            authorization.EnsureCanAccessInternalArea();
            authorization.EnsureUserInRole(Roles.InternalAdmin);

            Organisation organisation = await dataAccess.FetchOrganisationAsync(message.OrganisationData.Id);

            switch (message.OrganisationData.OrganisationType)
            {
            case Core.Organisations.OrganisationType.RegisteredCompany:
                organisation.UpdateRegisteredCompanyDetails(message.OrganisationData.Name, message.OrganisationData.CompanyRegistrationNumber, message.OrganisationData.TradingName);
                break;

            case Core.Organisations.OrganisationType.Partnership:
                organisation.UpdatePartnershipDetails(message.OrganisationData.TradingName);
                break;

            case Core.Organisations.OrganisationType.SoleTraderOrIndividual:
                organisation.UpdateSoleTraderDetails(message.OrganisationData.Name, message.OrganisationData.TradingName);
                break;
            }

            Country country = await dataAccess.FetchCountryAsync(message.OrganisationData.BusinessAddress.CountryId);

            Address address = new Address(
                message.OrganisationData.BusinessAddress.Address1,
                message.OrganisationData.BusinessAddress.Address2,
                message.OrganisationData.BusinessAddress.TownOrCity,
                message.OrganisationData.BusinessAddress.CountyOrRegion,
                message.OrganisationData.BusinessAddress.Postcode,
                country,
                message.OrganisationData.BusinessAddress.Telephone,
                message.OrganisationData.BusinessAddress.Email);

            organisation.AddOrUpdateAddress(AddressType.RegisteredOrPPBAddress, address);

            await dataAccess.SaveAsync();

            return(true);
        }