public static WizardFlyer SetFlyer(FlyerTypes flyerType) { var result = new WizardFlyer(flyerType); HttpContext.Current.Session[GetKey()] = result; return(result); }
public static WizardFlyer FromOrder(Order order) { if (order == null) { throw new Exception("order parameter is required"); } var result = WizardFlyer.SetFlyer((FlyerTypes)Enum.Parse(typeof(FlyerTypes), order.type, true)); if (order.order_id > 0) { result.OrderId = order.order_id; } Func <String, String> getStringValue = (value) => value.HasNoText() ? null : value; result.FlyerTitle = order.title.HasNoText() ? null : order.title.Trim(); result.EmailSubject = getStringValue(order.email_subject); if (result.FlyerTitle.HasText() && result.EmailSubject.HasText()) { result.FlyerTitleStepCompleted = true; } result.Name = getStringValue(order.field5) ?? Helper.GetCustomerNameByEmail(order.customer_id); result.Phone = getStringValue(order.field2); result.Ext = getStringValue(order.field3); result.Email = getStringValue(order.field1); if (result.Name.HasText() || result.Phone.HasText() || result.Email.HasText()) { result.ContactDetailsStepCompleted = true; } String offerType; String propertyType; if (order.PropertyCategory > 0) { ParsePropertyCategory(order.PropertyCategory, out offerType, out propertyType); result.OfferType = offerType; result.PropertyType = propertyType; result.PropertyCategoryId = order.PropertyCategory.ToString(); } if (order.PropertyType > 0) { result.ResidentialType = order.PropertyType.ToString(); } if (result.OfferType.HasText() && result.PropertyType.HasText() && result.ResidentialType.HasText()) { result.PropertyTypeStepCompleted = true; } result.StreetAddress = order.prop_address1.HasNoText() ? null : order.prop_address1.Trim(); result.AptSuiteBldg = getStringValue(order.AptSuiteBldg); result.City = order.prop_city.HasNoText() ? null : order.prop_city.Trim(); result.State = getStringValue(order.prop_state); result.ZipCode = getStringValue(order.prop_zipcode); result.MapLink = getStringValue(order.map_link); if (result.MapLink.HasText()) { result.AddMap = true; } if (result.StreetAddress.HasText() || result.AptSuiteBldg.HasText() || result.City.HasText() || result.State.HasText() || result.ZipCode.HasText()) { result.LocationStepCompleted = true; } result.Location = getStringValue(order.location); if (result.Location.HasText()) { result.DesiredLocationStepCompleted = true; } result.MlsNumber = getStringValue(order.mls_number); result.YearBuilt = getStringValue(order.YearBuilt); result.Subdivision = getStringValue(order.Subdivision); result.Hoa = getStringValue(order.HOA); result.Bedrooms = getStringValue(order.Bedrooms); result.Bathrooms = getStringValue(order.FullBaths); result.LotSize = getStringValue(order.LotSize); result.Sqft = getStringValue(order.SqFoots); result.Floors = getStringValue(order.Floors); result.Parking = getStringValue(order.Parking); result.OpenHouses = getStringValue(order.OpenHouses); result.Description = getStringValue(order.prop_desc); if (result.MlsNumber.HasText() || result.YearBuilt.HasText() || result.Subdivision.HasText() || result.Hoa.HasText() || result.Bedrooms.HasText() || result.Bathrooms.HasText() || result.LotSize.HasText() || result.Sqft.HasText() || result.Floors.HasText() || result.Parking.HasText() || result.OpenHouses.HasText() || result.Description.HasText()) { result.DescriptionStepCompleted = true; } if (result.FlyerType == FlyerTypes.Custom) { result.Link = getStringValue(order.virtualtour_link); } var amenities = result.GetType().GetProperties() .Where(p => p.GetCustomAttributes(typeof(AmenityAttribute), false).Length > 0) .ToDictionary(k => (k.GetCustomAttributes(typeof(DisplayNameAttribute), false)[0] as DisplayNameAttribute).DisplayName.ToLower(), v => v); if (order.PropertyFeatures.HasText() && order.PropertyFeaturesValues.HasText()) { var keys = order.PropertyFeatures.Split(':'); var values = order.PropertyFeaturesValues.Split(':'); Boolean value; if (keys.Length == values.Length) { for (var i = 0; i < keys.Length; i++) { if (amenities.ContainsKey(keys[i].ToLower())) { value = Boolean.Parse(values[i]); amenities[keys[i].ToLower()].SetValue(result, value, null); if (value) { result.AmenitiesStepCompleted = true; } } } } } var orderReflectionProperties = order.GetType().GetProperties().ToDictionary(k => k.Name, v => v); for (var i = 0; i < result.Photos.Length; i++) { var key = "photo" + (i + 1).ToString(); if (orderReflectionProperties.ContainsKey(key)) { result.Photos[i] = getStringValue(orderReflectionProperties[key].GetValue(order, null) as String); if (result.Photos[i].HasText()) { result.PhotoStepCompleted = true; } } } if (result.FlyerType == FlyerTypes.Custom) { result.PhotoStepCompleted = false; if (result.Photos[0].HasText()) { result.UploadFlyerStepCompleted = true; } } Decimal @decimal; if (order.prop_price.HasText()) { var split = order.prop_price.Split('|'); if (split.Length > 0) { result.PriceRent = getStringValue(split[0]); if (split.Length > 1) { if (Decimal.TryParse(split[1], out @decimal)) { result.Price = @decimal; } if (split.Length > 2) { result.PerArea = getStringValue(split[2]); if (split.Length > 3) { result.RentPeriod = getStringValue(split[3]); } } } } } if (result.PriceRent.HasText() || result.Price > 0 || result.PerArea.HasText() || result.RentPeriod.HasText()) { result.PriceStepCompleted = true; } if (order.price_range_min.HasText()) { if (Decimal.TryParse(order.price_range_min, out @decimal)) { result.PriceMin = @decimal; } } if (order.price_range_max.HasText()) { if (Decimal.TryParse(order.price_range_max, out @decimal)) { result.PriceMax = @decimal; } } if (result.PriceMin > 0 || result.PriceMax > 0) { result.PriceRangeStepCompleted = true; } result.Layout = getStringValue(order.layout); result.Markup = getStringValue(order.markup); if (result.Markup.HasText()) { result.ChooseFlyerStepCompleted = true; } result.MarketState = getStringValue(order.market_state); if (!order.delivery_date.Equals(default(DateTime))) { result.DeliveryDate = order.delivery_date; } String markets = null; if (getStringValue(order.market_county) != null) { result.MarketType = "county"; markets = order.market_county; } else if (getStringValue(order.market_association) != null) { result.MarketType = "association"; markets = order.market_association; } else if (getStringValue(order.market_msa) != null) { result.MarketType = "msa"; markets = order.market_msa; } if (result.MarketState.HasText() && result.MarketType.HasText() && markets.HasText()) { result.SelectedPricesList = PricesList.FromParameters(order, result.MarketType, markets); } if (result.SelectedPricesList != null && result.SelectedPricesList.Items.Count > 0) { result.SelectMarketAreaStepCompleted = true; } return(result); }