/// <summary>
        ///     Handles the specified request.
        /// </summary>
        /// <param name="request">The request.</param>
        /// <param name="response">The response.</param>
        protected override void Handle(AddDtoRequest <OrganizationPhoneDto> request, AddDtoResponse <OrganizationPhoneDto> response)
        {
            var organization          = _organizationRepository.GetByKey(UserContext.IsSystemAdmin ? request.AggregateKey : UserContext.OrganizationKey);
            var originalPhone         = organization.OrganizationPhones.FirstOrDefault(p => p.Key == request.DataTransferObject.OriginalHash);
            var organizationPhoneType = Lookup.Find <OrganizationPhoneType>(request.DataTransferObject.OrganizationPhoneType.Code);
            var phone = new Phone(request.DataTransferObject.Phone.Number, request.DataTransferObject.Phone.Extension);

            var organizationPhone = new OrganizationPhone(organizationPhoneType, phone, request.DataTransferObject.IsPrimary);

            if (originalPhone != organizationPhone)
            {
                if (originalPhone != null)
                {
                    organization.RemovePhone(originalPhone);
                }
                organization.AddPhone(organizationPhone);
            }
            else if (organizationPhone.IsPrimary)
            {
                organization.MakePrimary(organizationPhone);
            }

            response.AggregateKey           = organization.Key;
            response.DataTransferObject     = Mapper.Map <OrganizationPhone, OrganizationPhoneDto>(organizationPhone);
            response.DataTransferObject.Key = organization.Key;
        }
Esempio n. 2
0
        /// <summary>
        /// Handles the specified request.
        /// </summary>
        /// <param name="request">The request.</param>
        /// <param name="response">The response.</param>
        protected override void Handle(AddDtoRequest <OrganizationAddressDto> request, AddDtoResponse <OrganizationAddressDto> response)
        {
            var     organization = _organizationRepository.GetByKey(request.AggregateKey);
            var     addressDto   = request.DataTransferObject.Address;
            Address address      = null;

            try
            {
                address = new Address(addressDto.FirstStreetAddress,
                                      addressDto.SecondStreetAddress,
                                      addressDto.CityName,
                                      _lookupProvider.Find <StateProvince>(addressDto.StateProvince.Code),
                                      new PostalCode(addressDto.PostalCode));
            }
            catch (Exception ex)
            {
                response.DataTransferObject = new OrganizationAddressDto();
                response.DataTransferObject.AddDataErrorInfo(new DataErrorInfo(ex.Message, ErrorLevel.Error));
                return;
            }

            var organizationAddressType = _lookupProvider.Find <OrganizationAddressType> (request.DataTransferObject.OrganizationAddressType.Code);
            var organizationAddress     = new OrganizationAddress(organizationAddressType, address, request.DataTransferObject.IsPrimary);
            var originalAddress         = organization.OrganizationAddresses.FirstOrDefault(a => a.GetHashCode() == request.DataTransferObject.OriginalHash);

            if (originalAddress != organizationAddress)
            {
                if (originalAddress != null)
                {
                    organization.RemoveAddress(originalAddress);
                }
                organization.AddAddress(organizationAddress);
            }
            else if (organizationAddress.IsPrimary)
            {
                organization.MakePrimary(organizationAddress);
            }
            response.AggregateKey           = organization.Key;
            response.DataTransferObject     = Mapper.Map <OrganizationAddress, OrganizationAddressDto> (organizationAddress);
            response.DataTransferObject.Key = organization.Key;
        }
Esempio n. 3
0
        protected override void Handle(AddDtoRequest <OrganizationAddressDto> request, AddDtoResponse <OrganizationAddressDto> response)
        {
            var organization = _organizationRepository.GetByKey(UserContext.IsSystemAdmin ? request.AggregateKey : UserContext.OrganizationKey);
            var addressDto   = request.DataTransferObject.Address;
            var address      = new Address(addressDto.FirstStreetAddress,
                                           addressDto.SecondStreetAddress,
                                           addressDto.CityName,
                                           Lookup.Find <StateProvince>(addressDto.StateProvince.Code),
                                           new PostalCode(addressDto.PostalCode));

            var organizationAddressType = Lookup.Find <OrganizationAddressType>(request.DataTransferObject.OrganizationAddressType.Code);
            var organizationAddress     = new OrganizationAddress(organizationAddressType, address, request.DataTransferObject.IsPrimary);
            var originalAddress         = organization.OrganizationAddresses.FirstOrDefault(a => a.Key == request.DataTransferObject.OriginalHash);

            if (originalAddress != organizationAddress)
            {
                if (originalAddress != null)
                {
                    organization.RemoveAddress(originalAddress);
                }
                organization.AddAddress(organizationAddress);
            }
            else if (organizationAddress.IsPrimary)
            {
                organization.MakePrimary(organizationAddress);
            }
            response.AggregateKey           = organization.Key;
            response.DataTransferObject     = Mapper.Map <OrganizationAddress, OrganizationAddressDto>(organizationAddress);
            response.DataTransferObject.Key = organization.Key;
        }