Ejemplo n.º 1
0
        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();

            }
        }
Ejemplo n.º 2
0
        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();
            }
        }