private IEnumerable <ScienceSliderSchemaViewModel> GetSliderItemViewModels(IEnumerable <IPublishedContent> sliderItems) { var viewModels = new List <ScienceSliderSchemaViewModel>(); if (ExistenceUtility.IsNullOrEmpty(sliderItems)) { return(viewModels); } foreach (var section in sliderItems) { ScienceSliderSchemaViewModel viewModel = null; switch (section) { case ScienceSliderSchemaHeadingText headingText: viewModel = CreateHeadingTextSliderItem(headingText); break; case ScienceSliderSchemaImageText imageText: viewModel = CreateImageTextSliderItem(imageText); break; } if (viewModel != null) { viewModels.Add(viewModel); } } return(viewModels); }
private ScienceSliderSchemaViewModel CreateHeadingTextSliderItem(ScienceSliderSchemaHeadingText schema) { var model = new ScienceSliderSchemaViewModel(); model.Heading = schema.Heading; model.ImageTextSection = false; model.Text = schema.Text; return(model); }
private ScienceSliderSchemaViewModel CreateImageTextSliderItem(ScienceSliderSchemaImageText schema) { var model = new ScienceSliderSchemaViewModel(); model.ImageTextSection = true; model.Text = schema.Text; model.ImagePosition = schema.ImagePosition; if (schema.Image != null) { model.Image = new ImageViewModel() { Url = schema.Image.Url, AlternativeText = schema.Image.GetPropertyValue <string>("altText").IsNullOrWhiteSpace() ? schema.Image.Name : schema.Image.GetPropertyValue <string>("altText"), TitleText = schema.Image.GetPropertyValue <string>("titleText"), }; } else { model.Image = new ImageViewModel() { Url = null, AlternativeText = null, TitleText = null }; } if (schema.ImageLink != null) { model.ImageLink = new NavigationItemViewModel() { Url = schema.ImageLink.Url, Text = schema.ImageLink.Name, Target = schema.ImageLink.Target, }; } else { model.ImageLink = new NavigationItemViewModel() { Url = null, Text = null, Target = null }; } return(model); }