public static BI.ViewModels.FlightTraining GetFlightTrainingInfo() { List<DAL.application_page_setting> settings = new List<DAL.application_page_setting>(); BI.ViewModels.FlightTraining flightTrainingPage = new ViewModels.FlightTraining(); string page = DAL.Settings.Application_Pages.FlightTraining.ToString(); DAL.flyamericaEntities ctx = new DAL.flyamericaEntities(); int[] paragraphIds; char split = ','; try { settings = ctx.application_page_setting.Where(x => x.page == page).ToList(); paragraphIds = settings.Where(x => x.setting == DAL.Settings.FlightTraining_Page_Settings.PageParagraphs.ToString()) .Select(y => y.value).FirstOrDefault() .Split(split).Select(p => Convert.ToInt32(p)).ToArray(); var paragraphs = ctx.content_paragraph.Where(cp => paragraphIds.Any(y => paragraphIds.Contains(cp.id))) .GroupJoin ( ctx.assets, cp => cp.asset, a => a.id, (cp, r) => r .Select(par => new { text = cp.text, img = par.asset_name }) .DefaultIfEmpty( new {text = cp.text, img = "" }) ).SelectMany(r => r).ToList(); int image = Convert.ToInt32(settings.Where(x => x.setting == DAL.Settings.FlightTraining_Page_Settings.PageImage.ToString()).Select(y => y.value).FirstOrDefault()); flightTrainingPage.Image = ctx.assets.Where(x => x.id == image).Select(y => y.asset_name).FirstOrDefault(); flightTrainingPage.Title = settings.Where(x => x.setting == DAL.Settings.FlightTraining_Page_Settings.PageTitle.ToString()).Select(y => y.value).FirstOrDefault(); flightTrainingPage.ShortDescription = settings.Where(x => x.setting == DAL.Settings.FlightTraining_Page_Settings.ShortDescription.ToString()).Select(y => y.value).FirstOrDefault(); foreach (var item in paragraphs) { flightTrainingPage.Paragraphs.Add(new ViewModels.ParagraphSection { Image = item.img, Paragraph = item.text }); } return flightTrainingPage; } catch (Exception ex) { Exceptions.GetFlightTrainingException cmEX = new Exceptions.GetFlightTrainingException("Error retrieving Flight Training page info.", ex); logException(cmEX); throw cmEX; } }
public static BI.ViewModels.MainContent GetMainContent() { BI.ViewModels.MainContent content = new ViewModels.MainContent(); DAL.flyamericaEntities ctx = new DAL.flyamericaEntities(); string page = DAL.Settings.Application_Pages.Home.ToString(); string component = DAL.Settings.Home_Page_Components.MainPanel.ToString(); List<DAL.application_page_component_setting> settings = new List<DAL.application_page_component_setting>(); try { settings = ctx.application_page_component_setting.Where(x => x.component == component && x.page == page).ToList(); var contentItems = ctx.main_content_item.Where(mci => mci.active == true) .Join ( ctx.assets, mci => mci.asset, a => a.id, (mci, a) => new { maincontentitem = mci, asset = a } ) .Join ( ctx.application_page, contentitem => new { page = contentitem.maincontentitem.page, controller = contentitem.maincontentitem.controller, action = contentitem.maincontentitem.action }, appPage => new { page = appPage.page_name, controller = appPage.page_controller, action = appPage.page_action }, (contentitem, appPage) => new { contentitem, appPage } ).OrderBy(x => x.contentitem.maincontentitem.sequence).ToList(); foreach (var item in contentItems) { content.Items.Add(new ViewModels.MainContentItem { Image = item.contentitem.asset.asset_name, Title = item.appPage.page_link_text, Description = item.contentitem.maincontentitem.short_description, Controller = item.appPage.page_controller, Action = item.appPage.page_action }); } content.ItemVisibleMax = Convert.ToInt32(settings.Where(x => x.setting == DAL.Settings.Home_Page_Main_Panel_Settings.ItemVisibleMax.ToString()).Select(y => y.value).FirstOrDefault()); content.ItemVisibleMin = Convert.ToInt32(settings.Where(x => x.setting == DAL.Settings.Home_Page_Main_Panel_Settings.ItemVisibleMin.ToString()).Select(y => y.value).FirstOrDefault()); content.Mousewheel = Convert.ToBoolean(settings.Where(x => x.setting == DAL.Settings.Home_Page_Main_Panel_Settings.Mousewheel.ToString()).Select(y => y.value).FirstOrDefault()); content.Paginate = Convert.ToBoolean(settings.Where(x => x.setting == DAL.Settings.Home_Page_Main_Panel_Settings.Paginate.ToString()).Select(y => y.value).FirstOrDefault()); content.Scroll = Convert.ToInt32(settings.Where(x => x.setting == DAL.Settings.Home_Page_Main_Panel_Settings.Scroll.ToString()).Select(y => y.value).FirstOrDefault()); return content; } catch (Exception ex) { Exceptions.GetMainContentException cmEx = new Exceptions.GetMainContentException("Error retrieving main content", ex); logException(cmEx); throw cmEx; } finally { ctx.Dispose(); } }
public static BI.ViewModels.HomePage GetHomePage() { DAL.flyamericaEntities ctx = new DAL.flyamericaEntities(); string page = DAL.Settings.Application_Pages.Home.ToString(); string component = DAL.Settings.Home_Page_Components.SliderPanel.ToString(); BI.ViewModels.HomePage homePage = new ViewModels.HomePage(); List<DAL.asset> images = new List<DAL.asset>(); List<DAL.application_page_setting> settings = new List<DAL.application_page_setting>(); List<DAL.application_page_component_setting> sliderSettings = new List<DAL.application_page_component_setting>(); try { //try wrapped for db calls try { settings = ctx.application_page_setting.Where(x => x.page == page).ToList(); sliderSettings = ctx.application_page_component_setting.Where(x => x.component == component && x.page == page).ToList(); images = ctx.assets.Join ( ctx.component_image, a => a.id, ci => ci.asset, (a, ci) => new { a = a, ci = ci } ) .Where(x => x.ci.isActive == true && x.ci.page == page && x.ci.component == component) .Select(z => z.a).ToList(); } catch (Exception ex) { BI.Content.Exceptions.GetHomePageException cmEx = new Exceptions.GetHomePageException("Error Retrieving Home Page data from the database.", ex); logException(cmEx); throw cmEx; } //try wrapped for processing db records try { homePage.ShowSliderPanel = Convert.ToBoolean(settings.Where(x => x.setting == DAL.Settings.Home_Page_Settings.ShowSliderPanel.ToString()).Select(y => y.value).FirstOrDefault()); homePage.ShowMainPanel = Convert.ToBoolean(settings.Where(x => x.setting == DAL.Settings.Home_Page_Settings.ShowMainPanel.ToString()).Select(y => y.value).FirstOrDefault()); homePage.ShowAccessoryPanel = Convert.ToBoolean(settings.Where(x => x.setting == DAL.Settings.Home_Page_Settings.ShowAccessoryPanel.ToString()).Select(y => y.value).FirstOrDefault()); homePage.ShowFeaturedPanel = Convert.ToBoolean(settings.Where(x => x.setting == DAL.Settings.Home_Page_Settings.ShowFeaturedPanel.ToString()).Select(y => y.value).FirstOrDefault()); homePage.HomePageSlider.HasThumbnails = Convert.ToBoolean(sliderSettings.Where(x => x.setting == DAL.Settings.Home_Page_Slider_Settings.HasThumbnails.ToString()).Select(y => y.value).FirstOrDefault()); homePage.HomePageSlider.Paginate = Convert.ToBoolean(sliderSettings.Where(x => x.setting == DAL.Settings.Home_Page_Slider_Settings.Paginate.ToString()).Select(y => y.value).FirstOrDefault()); homePage.HomePageSlider.ShowLoader = Convert.ToBoolean(sliderSettings.Where(x => x.setting == DAL.Settings.Home_Page_Slider_Settings.ShowLoader.ToString()).Select(y => y.value).FirstOrDefault()); homePage.HomePageSlider.ShowCaption = Convert.ToBoolean(sliderSettings.Where(x => x.setting == DAL.Settings.Home_Page_Slider_Settings.ShowCaption.ToString()).Select(y => y.value).FirstOrDefault()); foreach (DAL.asset img in images) { homePage.HomePageSlider.Images.Add(new ViewModels.SliderImage { Image = img.asset_name, AltText = img.description }); } } catch (Exception ex) { BI.Content.Exceptions.GetHomePageException cmEx = new Exceptions.GetHomePageException("Error parsing homepage data to the model.", ex); logException(cmEx); throw cmEx; } return homePage; } catch (Exception ex) { throw ex; } finally { ctx.Dispose(); } }