/// <summary>
        /// Determines the new customer's property status.
        /// </summary>
        /// <param name="submitted">The submitted.</param>
        /// <param name="current">The current.</param>
        /// <returns></returns>
        private CustomerPropertyStatus DetermineNewCustomerPropertyStatus(CustomerPropertyStatus submitted, CustomerPropertyStatus current)
        {
            if (submitted == CustomerPropertyStatus.IOwnThisPropertyAndOtherProperties || current == CustomerPropertyStatus.IOwnThisPropertyAndOtherProperties)
            {
                return(CustomerPropertyStatus.IOwnThisPropertyAndOtherProperties);
            }

            if (submitted == CustomerPropertyStatus.IHomeOwner || current == CustomerPropertyStatus.IHomeOwner)
            {
                if (submitted == CustomerPropertyStatus.ILiveInTheAboveAndOwnOtherProperties ||
                    current == CustomerPropertyStatus.ILiveInTheAboveAndOwnOtherProperties)
                {
                    return(CustomerPropertyStatus.IOwnThisPropertyAndOtherProperties);
                }

                return(CustomerPropertyStatus.IHomeOwner);
            }

            if (submitted == CustomerPropertyStatus.ILiveInTheAboveAndOwnOtherProperties ||
                current == CustomerPropertyStatus.ILiveInTheAboveAndOwnOtherProperties)
            {
                return(CustomerPropertyStatus.ILiveInTheAboveAndOwnOtherProperties);
            }

            return(CustomerPropertyStatus.NotYetFilled);
        }
        /// <summary>
        /// Fills the customer property status and time at address and get addresses.
        /// </summary>
        /// <param name="command">The command.</param>
        /// <param name="customer">The customer.</param>
        /// <param name="customerId">The customer identifier.</param>
        /// <returns></returns>
        private IEnumerable <CustomerAddress> FillCustomerPropertyStatusAndTimeAtAddressAndGetAddresses(CustomerUpdateCommand command, Customer customer, int customerId)
        {
            bool?       isOwnsCurrentAdress       = null;
            bool?       isOwnsPreviousAddress     = null;
            bool?       isOwnsAdditionalProperty  = null;
            HousingType?currentAddressHousingType = null;

            var curLivingAddress = command.CurrentLivingAddress
                                   .AsOptional()
                                   .IfNotEmpty(o => {
                isOwnsCurrentAdress = o.IsOwns;     //Fills time at address
                customer.PersonalInfo.TimeAtAddress = o.MonthsAtAddress.IsNotEmpty() ? int.Parse(o.MonthsAtAddress) : (int?)null;
                currentAddressHousingType           = o.HousingType;
            })
                                   .Map(o => ConvertToCustomerAddress(o, customerId))
                                   .IfNotEmpty(addr => addr.addressType = CustomerAddressType.PersonalAddress);

            var previousLivingAddress = command.PreviousLivingAddress
                                        .AsOptional()
                                        .IfNotEmpty(o => isOwnsPreviousAddress = o.IsOwns)
                                        .Map(o => ConvertToCustomerAddress(o, customerId))
                                        .IfNotEmpty(addr => addr.addressType = CustomerAddressType.PrevPersonAddresses);

            var additionalOwnedPropertyAddresses = command.AdditionalOwnedProperties
                                                   .AsOptionals()
                                                   .IfAnyNotEmpty(() => isOwnsAdditionalProperty = true)
                                                   .MapMany(o => {
                var addr         = ConvertToCustomerAddress(o, customerId);
                addr.addressType = CustomerAddressType.OtherPropertyAddress;
                return(addr);
            });

            CustomerPropertyStatus submitted = DetermineSubmittedPropertyStatus(currentAddressHousingType, isOwnsCurrentAdress, isOwnsPreviousAddress, isOwnsAdditionalProperty);
            CustomerPropertyStatus final     = DetermineNewCustomerPropertyStatus(submitted, (CustomerPropertyStatus)customer.PersonalInfo.PropertyStatus);

            customer.PersonalInfo.PropertyStatus = (int)final;

            var addresses = curLivingAddress.Concat(previousLivingAddress)
                            .Concat(additionalOwnedPropertyAddresses.SelectMany(o => o));

            return(addresses);
        }
Example #3
0
        //TODO: check it out
        private HousingType DetermineHousingType(CustomerAddressType addressType, CustomerPropertyStatus propertyStatus)
        {
            if (addressType == CustomerAddressType.PersonalAddress)
            {
                switch (propertyStatus)
                {
                case CustomerPropertyStatus.NotYetFilled://should not happen because we require to supply HousingType
                    Log.Error("Got not yet filled");
                    break;

                case CustomerPropertyStatus.IOwnOnlyThisProperty:
                    return(HousingType.OwnProperty);

                case CustomerPropertyStatus.IOwnThisPropertyAndOtherProperties:
                    return(HousingType.OwnProperty);

                case CustomerPropertyStatus.ILiveInTheAboveAndOwnOtherProperties:
                    // could not determine
                    break;

                case CustomerPropertyStatus.IHomeOwner:
                    return(HousingType.OwnProperty);

                case CustomerPropertyStatus.Renting:
                    return(HousingType.Renting);

                case CustomerPropertyStatus.SocialHouse:
                    return(HousingType.Social);

                case CustomerPropertyStatus.LivingWithParents:
                    return(HousingType.LivingWithParents);

                default:
                    throw new ArgumentOutOfRangeException("propertyStatus", propertyStatus, null);
                }
            }

            if (addressType == CustomerAddressType.PrevPersonAddresses)
            {
                switch (propertyStatus)
                {
                case CustomerPropertyStatus.NotYetFilled:    //should not happen because we require to supply HousingType
                    Log.Error("Got not yet filled");
                    break;

                case CustomerPropertyStatus.IOwnOnlyThisProperty:
                    //could not determine
                    return(HousingType.OwnProperty);

                case CustomerPropertyStatus.IOwnThisPropertyAndOtherProperties:
                    //could not determine
                    return(HousingType.OwnProperty);

                case CustomerPropertyStatus.ILiveInTheAboveAndOwnOtherProperties:
                    // could not determine
                    break;

                case CustomerPropertyStatus.IHomeOwner:
                    // could not determine
                    return(HousingType.OwnProperty);

                case CustomerPropertyStatus.Renting:
                    // could not determine
                    return(HousingType.Renting);

                case CustomerPropertyStatus.SocialHouse:
                    //could not determine
                    return(HousingType.Social);

                case CustomerPropertyStatus.LivingWithParents:
                    //could not determine
                    return(HousingType.LivingWithParents);

                default:
                    throw new ArgumentOutOfRangeException("propertyStatus", propertyStatus, null);
                }
            }

            return(HousingType.OwnProperty);
        }