public void Setup(PageModel pageModel, MediaModel mediaModel, LayoutModel layoutModel)
        {

            SetupEcommerceLayoutWidgets(mediaModel, layoutModel);
            SetupHomeLayoutWidgets(pageModel, mediaModel, layoutModel);
            SetupSearchLayoutWidgets(pageModel, layoutModel);
            SetupCheckoutLayoutWidgets(mediaModel, layoutModel);
            SetupProductLayoutWidgets(layoutModel, pageModel);
        }
        private void SetupProductLayoutWidgets(LayoutModel layoutModel, PageModel pageModel)
        {
            var breadcrumbs = new BreadCrumb
            {
                LayoutArea = layoutModel.ProductLayout.LayoutAreas.Single(x => x.AreaName == "Before Product Content"),
                Name = "Breadcrumbs",
                IsRecursive = true,
                Cache = true,
                CacheExpiryType = CacheExpiryType.Sliding,
                CacheLength = 180
            };
            _widgetService.AddWidget(breadcrumbs);

            var relatedProducts = new RelatedProducts
            {
                LayoutArea = layoutModel.ProductLayout.LayoutAreas.Single(x => x.AreaName == "After Product Content"),
                Name = "Related Products",
                Cache = true,
                CacheExpiryType = CacheExpiryType.Absolute,
                CacheLength = 1800
            };
            _widgetService.AddWidget(relatedProducts);

            var peopleAlsoBought = new PeopleWhoBoughtThisAlsoBought
            {
                LayoutArea = layoutModel.ProductLayout.LayoutAreas.Single(x => x.AreaName == "After Product Content"),
                Name = "People who bought this also bought",
                Cache = true,
                CacheExpiryType = CacheExpiryType.Absolute,
                CacheLength = 1800
            };
            _widgetService.AddWidget(peopleAlsoBought);

            var otherCategories = new NotWhatYouWereLookingForWidget
            {
                LayoutArea = layoutModel.ProductLayout.LayoutAreas.Single(x => x.AreaName == "Below Product Price"),
                Name = "Not what you were looking for?",
                Cache = true,
                CacheExpiryType = CacheExpiryType.Absolute,
                CacheLength = 1800
            };
            _widgetService.AddWidget(otherCategories);
        }
        private void SetupCheckoutLayoutWidgets(MediaModel mediaModel, LayoutModel layoutModel)
        {
            //checkout images
            var checkoutLogo = new LinkedImage
            {
                Image = _fileService.GetFileLocation(mediaModel.Logo, new Size { Width = 200, Height = 200 }),
                Link = "/",
                LayoutArea = layoutModel.CheckoutLayout.LayoutAreas.Single(x => x.AreaName == "Checkout Header Left"),
                Cache = true,
                CacheExpiryType = CacheExpiryType.Sliding,
                CacheLength = 60
            };
            _widgetService.AddWidget(checkoutLogo);

            var checkoutSecureBadge = new LinkedImage
            {
                Image = mediaModel.SecureCheckout.FileUrl,
                LayoutArea = layoutModel.CheckoutLayout.LayoutAreas.Single(x => x.AreaName == "Checkout Header Middle"),
                Cache = true,
                CacheExpiryType = CacheExpiryType.Sliding,
                CacheLength = 60
            };
            _widgetService.AddWidget(checkoutSecureBadge);
        }
        public LayoutModel Setup(MediaModel mediaModel)
        {
            var layoutModel = new LayoutModel();
            //base layout
            var baseLayout = new Layout
            {
                Name = "Base Ecommerce Layout",
                UrlSegment = "_BaseEcommerceLayout",
                LayoutAreas = new List<LayoutArea>(),
            };
            _documentService.AddDocument(baseLayout);

            //ecommerce main layout
            var eCommerceLayout = new Layout
            {
                Name = "Ecommerce Layout",
                UrlSegment = "_EcommerceLayout",
                LayoutAreas = new List<LayoutArea>(),
                Parent = baseLayout
            };
            var ecommerceLayoutArea = new List<LayoutArea>
            {
                new LayoutArea {AreaName = "Header Left", Layout = eCommerceLayout},
                new LayoutArea {AreaName = "Header Middle", Layout = eCommerceLayout},
                new LayoutArea {AreaName = "Header Right", Layout = eCommerceLayout},
                new LayoutArea {AreaName = "User Links", Layout = eCommerceLayout},
                new LayoutArea {AreaName = "Navigation", Layout = eCommerceLayout},
                new LayoutArea {AreaName = "Before Content", Layout = eCommerceLayout},
                new LayoutArea {AreaName = "After Content", Layout = eCommerceLayout},
                new LayoutArea {AreaName = "Footer Area 1", Layout = eCommerceLayout},
                new LayoutArea {AreaName = "Footer Area 2", Layout = eCommerceLayout},
                new LayoutArea {AreaName = "Footer Area 3", Layout = eCommerceLayout},
                new LayoutArea {AreaName = "Footer Area 4", Layout = eCommerceLayout}
            };

            _documentService.AddDocument(eCommerceLayout);
            foreach (LayoutArea area in ecommerceLayoutArea)
                _layoutAreaAdminService.SaveArea(area);

            layoutModel.EcommerceLayout = eCommerceLayout;

            var homeLayout = new Layout
            {
                Name = "Home Layout",
                UrlSegment = "_HomeLayout",
                LayoutAreas = new List<LayoutArea>(),
                Parent = eCommerceLayout
            };
            var homeLayoutAreas = new List<LayoutArea>
            {
                new LayoutArea {AreaName = "Home After Content", Layout = homeLayout},
                new LayoutArea {AreaName = "Teaser1", Layout = homeLayout},
                new LayoutArea {AreaName = "Teaser2", Layout = homeLayout},
                new LayoutArea {AreaName = "Teaser3", Layout = homeLayout},
                new LayoutArea {AreaName = "Teaser4", Layout = homeLayout}
            };
            _documentService.AddDocument(homeLayout);
            foreach (LayoutArea area in homeLayoutAreas)
                _layoutAreaAdminService.SaveArea(area);
            layoutModel.HomeLayout = homeLayout;
            //checkout layout
            var checkoutLayout = new Layout
            {
                Name = "Checkout Layout",
                UrlSegment = "_CheckoutLayout",
                LayoutAreas = new List<LayoutArea>(),
                Parent = eCommerceLayout
            };
            var checkoutLayoutAreas = new List<LayoutArea>
            {
                new LayoutArea {AreaName = "Checkout Header Left", Layout = checkoutLayout},
                new LayoutArea {AreaName = "Checkout Header Middle", Layout = checkoutLayout},
                new LayoutArea {AreaName = "Checkout Header Right", Layout = checkoutLayout},
                new LayoutArea {AreaName = "Checkout Footer Left", Layout = checkoutLayout},
                new LayoutArea {AreaName = "Checkout Footer Right", Layout = checkoutLayout}
            };
            _documentService.AddDocument(checkoutLayout);

            foreach (LayoutArea area in checkoutLayoutAreas)
                _layoutAreaAdminService.SaveArea(area);
            layoutModel.CheckoutLayout = checkoutLayout;
            //product layout
            var productLayout = new Layout
            {
                Name = "Product Layout",
                UrlSegment = "_ProductLayout",
                LayoutAreas = new List<LayoutArea>(),
                Parent = eCommerceLayout
            };
            var productLayoutAreas = new List<LayoutArea>
            {
                new LayoutArea {AreaName = "Below Product Price", Layout = productLayout},
                new LayoutArea {AreaName = "Below Add to cart", Layout = productLayout},
                new LayoutArea {AreaName = "Below Product Information", Layout = productLayout},
                new LayoutArea {AreaName = "Before Product Content", Layout = productLayout},
                new LayoutArea {AreaName = "After Product Content", Layout = productLayout}
            };

            _documentService.AddDocument(productLayout);
            foreach (LayoutArea area in productLayoutAreas)
                _layoutAreaAdminService.SaveArea(area);
            layoutModel.ProductLayout = productLayout;
            //category/search layout
            var searchLayout = new Layout
            {
                Name = "Search Layout",
                UrlSegment = "_SearchLayout",
                LayoutAreas = new List<LayoutArea>(),
                Parent = eCommerceLayout
            };
            var searchLayoutAreas = new List<LayoutArea>
            {
                new LayoutArea {AreaName = "Before Filters", Layout = searchLayout},
                new LayoutArea {AreaName = "After Filters", Layout = searchLayout}
            };

            _documentService.AddDocument(searchLayout);
            foreach (LayoutArea area in searchLayoutAreas)
                _layoutAreaAdminService.SaveArea(area);
            layoutModel.SearchLayout = searchLayout;

            var contentLayout = new Layout
            {
                Name = "Content Layout",
                UrlSegment = "_ContentLayout",
                LayoutAreas = new List<LayoutArea>(),
                Parent = eCommerceLayout
            };
            _documentService.AddDocument(contentLayout);
            layoutModel.ContentLayout = contentLayout;

            // UserAccount
            var userAccountLayout = new Layout
            {
                Name = "User Account Layout",
                UrlSegment = "_UserAccountLayout",
                LayoutAreas = new List<LayoutArea>(),
                Parent = eCommerceLayout
            };
            var userAccountAreas = new List<LayoutArea>
            {
                new LayoutArea {AreaName = "Right Column", Layout = userAccountLayout}
            };
            _documentService.AddDocument(userAccountLayout);
            foreach (LayoutArea area in userAccountAreas)
                _layoutAreaAdminService.SaveArea(area);
            layoutModel.UserAccountLayout = userAccountLayout;

            //Page templates
            var homeTemplate = new PageTemplate
            {
                Name = "Home Page",
                PageType = typeof (TextPage).FullName,
                UrlGeneratorType = typeof(DefaultWebpageUrlGenerator).FullName,
                Layout = homeLayout
            };
            _pageTemplateAdminService.Add(homeTemplate);

            SetPageDefaults(layoutModel);

            return layoutModel;
        }
        private void SetPageDefaults(LayoutModel layoutModel)
        {
            //product search
            string generatorTypeName = typeof(DefaultWebpageUrlGenerator).FullName;

            _pageDefaultsAdminService.SetDefaults(new DefaultsInfo
            {
                PageTypeName = typeof(ProductSearch).FullName,
                LayoutId = layoutModel.SearchLayout.Id,
                GeneratorTypeName = generatorTypeName
            });
            //checkout
            _pageDefaultsAdminService.SetDefaults(new DefaultsInfo
            {
                PageTypeName = typeof(EnterOrderEmail).FullName,
                LayoutId = layoutModel.CheckoutLayout.Id,
                GeneratorTypeName = generatorTypeName
            });
            _pageDefaultsAdminService.SetDefaults(new DefaultsInfo
            {
                PageTypeName = typeof(OrderPlaced).FullName,
                LayoutId = layoutModel.CheckoutLayout.Id,
                GeneratorTypeName = generatorTypeName
            });
            _pageDefaultsAdminService.SetDefaults(new DefaultsInfo
            {
                PageTypeName = typeof(PaymentDetails).FullName,
                LayoutId = layoutModel.CheckoutLayout.Id,
                GeneratorTypeName = generatorTypeName
            });
            _pageDefaultsAdminService.SetDefaults(new DefaultsInfo
            {
                PageTypeName = typeof(SetShippingDetails).FullName,
                LayoutId = layoutModel.CheckoutLayout.Id,
                GeneratorTypeName = generatorTypeName
            });
            // product
            _pageDefaultsAdminService.SetDefaults(new DefaultsInfo
            {
                PageTypeName = typeof(Product).FullName,
                LayoutId = layoutModel.ProductLayout.Id,
                GeneratorTypeName = typeof(ProductUrlGenerator).FullName
            });
            // category
            _pageDefaultsAdminService.SetDefaults(new DefaultsInfo
            {
                PageTypeName = typeof(Category).FullName,
                GeneratorTypeName = typeof(CategoryWithHierarchyUrlGenerator).FullName
            });
            // brand
            _pageDefaultsAdminService.SetDefaults(new DefaultsInfo
            {
                PageTypeName = typeof(Brand).FullName,
                GeneratorTypeName = typeof(BrandUrlGenerator).FullName
            });


            // UserAccount Pages

            _pageDefaultsAdminService.SetDefaults(new DefaultsInfo
            {
                PageTypeName = typeof(UserAccountInfo).FullName,
                LayoutId = layoutModel.UserAccountLayout.Id,
                GeneratorTypeName = generatorTypeName
            });
            _pageDefaultsAdminService.SetDefaults(new DefaultsInfo
            {
                PageTypeName = typeof(UserAccountChangePassword).FullName,
                LayoutId = layoutModel.UserAccountLayout.Id,
                GeneratorTypeName = generatorTypeName
            });
            _pageDefaultsAdminService.SetDefaults(new DefaultsInfo
            {
                PageTypeName = typeof(UserAccountAddresses).FullName,
                LayoutId = layoutModel.UserAccountLayout.Id,
                GeneratorTypeName = generatorTypeName
            });
            _pageDefaultsAdminService.SetDefaults(new DefaultsInfo
            {
                PageTypeName = typeof(UserAccountOrders).FullName,
                LayoutId = layoutModel.UserAccountLayout.Id,
                GeneratorTypeName = generatorTypeName
            });
            _pageDefaultsAdminService.SetDefaults(new DefaultsInfo
            {
                PageTypeName = typeof(UserAccountReviews).FullName,
                LayoutId = layoutModel.UserAccountLayout.Id,
                GeneratorTypeName = generatorTypeName
            });
            _pageDefaultsAdminService.SetDefaults(new DefaultsInfo
            {
                PageTypeName = typeof(UserAccountRewardPoints).FullName,
                LayoutId = layoutModel.UserAccountLayout.Id,
                GeneratorTypeName = generatorTypeName
            });
        }
        private void SetupEcommerceLayoutWidgets(MediaModel mediaModel, LayoutModel layoutModel)
        {
            var linkedImageLogo = new LinkedImage
            {
                Name = "Logo",
                Link = "/",
                Image = mediaModel.Logo.FileUrl,
                LayoutArea = layoutModel.EcommerceLayout.LayoutAreas.Single(x => x.AreaName == "Header Left"),
                Cache = true,
                CacheExpiryType = CacheExpiryType.Sliding,
                CacheLength = 60
            };
            _widgetService.AddWidget(linkedImageLogo);
            // Search
            var searchBox = new SearchBox
            {
                Name = "Search",
                LayoutArea = layoutModel.EcommerceLayout.LayoutAreas.Single(x => x.AreaName == "Header Middle"),
                Cache = true,
            };
            _widgetService.AddWidget(searchBox);

            // Ecommerce user links
            var userLinks = new EcommerceUserLinks
            {
                Name = "Ecommerce User Links",
                LayoutArea = layoutModel.EcommerceLayout.LayoutAreas.Single(x => x.AreaName == "User Links")
            };
            _widgetService.AddWidget(userLinks);

            //cart widget
            var cartWidget = new CartWidget
            {
                Name = "Cart Widget",
                LayoutArea = layoutModel.EcommerceLayout.LayoutAreas.Single(x => x.AreaName == "Header Right")
            };
            _widgetService.AddWidget(cartWidget);

            //footer links
            var footerLinksWidget = new TextWidget
            {
                LayoutArea = layoutModel.EcommerceLayout.LayoutAreas.Single(x => x.AreaName == "Footer Area 1"),
                Name = "Footer links",
                Text = EcommerceInstallInfo.FooterText1,
                Cache = true,
                CacheExpiryType = CacheExpiryType.Sliding,
                CacheLength = 60
            };
            _widgetService.AddWidget(footerLinksWidget);

            footerLinksWidget = new TextWidget
            {
                LayoutArea = layoutModel.EcommerceLayout.LayoutAreas.Single(x => x.AreaName == "Footer Area 2"),
                Name = "Footer links",
                Text = EcommerceInstallInfo.FooterText2,
                Cache = true,
                CacheExpiryType = CacheExpiryType.Sliding,
                CacheLength = 60
            };
            _widgetService.AddWidget(footerLinksWidget);

            footerLinksWidget = new TextWidget
            {
                LayoutArea = layoutModel.EcommerceLayout.LayoutAreas.Single(x => x.AreaName == "Footer Area 3"),
                Name = "Footer links",
                Text = EcommerceInstallInfo.FooterText3,
                Cache = true,
                CacheExpiryType = CacheExpiryType.Sliding,
                CacheLength = 60
            };
            _widgetService.AddWidget(footerLinksWidget);

            var afterContentCardsTeaser = new TextWidget
            {
                LayoutArea = layoutModel.EcommerceLayout.LayoutAreas.Single(x => x.AreaName == "After Content"),
                Name = "Footer links",
                Text = EcommerceInstallInfo.AfterContentCardsTeaser,
                Cache = true,
                CacheExpiryType = CacheExpiryType.Sliding,
                CacheLength = 60
            };

            _widgetService.AddWidget(afterContentCardsTeaser);

            var page404 = _documentService.GetDocumentByUrl<TextPage>("404");
            var notFoundProducts = new On404SearchWidget
            {
                LayoutArea = layoutModel.EcommerceLayout.LayoutAreas.Single(x => x.AreaName == "After Content"),
                Name = "What about these?",
                Cache = true,
                CacheExpiryType = CacheExpiryType.Sliding,
                CacheLength = 60,
                Webpage = page404
            };
            _widgetService.AddWidget(notFoundProducts);
        }
        private void SetupHomeLayoutWidgets(PageModel pageModel, MediaModel mediaModel, LayoutModel layoutModel)
        {
            var layout = layoutModel.HomeLayout;
            var beforeContent = layoutModel.EcommerceLayout.LayoutAreas.FirstOrDefault(x => x.AreaName == "Before Content");
            var teaser1Area = layout.LayoutAreas.FirstOrDefault(x => x.AreaName == "Teaser1");
            var teaser2Area = layout.LayoutAreas.FirstOrDefault(x => x.AreaName == "Teaser2");
            var teaser3Area = layout.LayoutAreas.FirstOrDefault(x => x.AreaName == "Teaser3");
            var teaser4Area = layout.LayoutAreas.FirstOrDefault(x => x.AreaName == "Teaser4");

            var slider = new Slider
            {
                Image = mediaModel.SliderImage1.FileUrl,
                Image1 = mediaModel.SliderImage2.FileUrl,
                LayoutArea = beforeContent,
                Webpage = pageModel.HomePage,
                Cache = true,
                CacheExpiryType = CacheExpiryType.Sliding,
                CacheLength = 1800
            };
            _widgetService.AddWidget(slider);

            var featuredProducts = new FeaturedProducts
            {
                LayoutArea = beforeContent,
                Webpage = pageModel.HomePage,
                ListOfFeaturedProducts = GetFeaturedProducts(),
                Name = "Featured Products",
                Cache = true,
                CacheExpiryType = CacheExpiryType.Sliding,
                CacheLength = 1800
            };
            _widgetService.AddWidget(featuredProducts);

            //nav
            var nav = new MobileFriendlyNavigation.Widgets.MobileFriendlyNavigation
            {
                Name = "Navigation",
                LayoutArea = layoutModel.EcommerceLayout.LayoutAreas.Single(x => x.AreaName == ("Navigation")),
                IncludeChildren = true,
                Cache = true,
                CacheExpiryType = CacheExpiryType.Sliding,
                CacheLength = 60
            };
            _widgetService.AddWidget(nav);

            var featuredCategories = new FeaturedCategories
            {
                LayoutArea = beforeContent,
                Webpage = pageModel.HomePage,
                ListOfFeaturedCategories = GetFeaturedCategories(),
                Name = "Featured Categories",
                Cache = true,
                CacheExpiryType = CacheExpiryType.Sliding,
                CacheLength = 1800
            };
            _widgetService.AddWidget(featuredCategories);

            var teaser1 = new TextWidget()
            {
                LayoutArea = teaser1Area,
                Webpage = pageModel.HomePage,
                Text = string.Format(@"<div class=""padding-bottom-10""><span><img src=""{0}"" /> </span></div><h3><a href=""#"">FREE delivery on orders over &pound;50. </a></h3><p>Orders placed Monday to Friday before 2pm will generally be picked and packed for immediate despatch. Please note that orders placed over the weekend or on public holidays will be processed on the next working day.</p>", mediaModel.DeliveryIcon.FileUrl),
                Cache = true,
                CacheExpiryType = CacheExpiryType.Sliding,
                CacheLength = 1800
                
            };
            _widgetService.AddWidget(teaser1);

            var teaser2 = new TextWidget()
            {
                LayoutArea = teaser2Area,
                Webpage = pageModel.HomePage,
                Text = string.Format(@"<div class=""padding-bottom-10""><span><img src=""{0}"" /> </span></div><h3><a href=""#"">7 day no question returns.</a></h3><p>We offer a 28 Day Money Back Guarantee. If for any reason you are not completely delighted with your purchase you may download a Returns Form and return it within 28 days of receipt for a full refund or exchange.</p>", mediaModel.ReturnIcon.FileUrl),
                Cache = true,
                CacheExpiryType = CacheExpiryType.Sliding,
                CacheLength = 1800
                
            };
            _widgetService.AddWidget(teaser2);

            var teaser3 = new TextWidget()
            {
                LayoutArea = teaser3Area,
                Webpage = pageModel.HomePage,
                Text = string.Format(@"<div class=""padding-bottom-10""><span><img src=""{0}"" /> </span></div><h3><a href=""#"">Store locations.</a></h3><p>Use our store locator to find a store near you as well as information like opening times, addresses, maps and a list of facilities available at every store.</p>", mediaModel.LocationIcon.FileUrl),
                Cache = true,
                CacheExpiryType = CacheExpiryType.Sliding,
                CacheLength = 1800
                
            };
            _widgetService.AddWidget(teaser3);

            var teaser4 = new TextWidget()
            {
                LayoutArea = teaser4Area,
                Webpage = pageModel.HomePage,
                Text = string.Format(@"<div class=""padding-bottom-10""><span><img src=""{0}"" /> </span></div><h3><a href=""#"">Contact us.</a></h3><p>Our customer service team is always willing to answer your proposal concerning Samsung Service. Your message will be promptly handled under the direct supervision of our executive management.</p>", mediaModel.ContactIcon.FileUrl),
                Cache = true,
                CacheExpiryType = CacheExpiryType.Sliding,
                CacheLength = 60
            };
            _widgetService.AddWidget(teaser4);

            GetFormProperties(pageModel.HomePage);
            //home footer form
            var footerLinksWidgetForm = new TextWidget
            {
                LayoutArea = layoutModel.EcommerceLayout.LayoutAreas.Single(x => x.AreaName == "Footer Area 4"),
                Name = "Footer links",
                Text = string.Format("[form-{0}]", pageModel.HomePage.Id),
                Cache = true,
                CacheExpiryType = CacheExpiryType.Sliding,
                CacheLength = 60
            };
            _widgetService.AddWidget(footerLinksWidgetForm);
        }
        private void SetupSearchLayoutWidgets(PageModel pageModel, LayoutModel layoutModel)
        {
            var recentlyViewed = new RecentlyViewedItems
            {
                Webpage = pageModel.ProductSearch,
                LayoutArea = layoutModel.SearchLayout.LayoutAreas.FirstOrDefault(x => x.AreaName == "After Filters"),
                Name = "Recently Viewed"
            };
            _widgetService.AddWidget(recentlyViewed);

            //breadcrumb
            var breadcrumbs = new BreadCrumb
            {
                LayoutArea = layoutModel.EcommerceLayout.LayoutAreas.Single(x => x.AreaName == "Before Content"),
                Name = "Breadcrumbs",
                Webpage = pageModel.ProductSearch,
                IsRecursive = true,
                Cache = true,
                CacheExpiryType = CacheExpiryType.Sliding,
                CacheLength = 1800
            };
            _widgetService.AddWidget(breadcrumbs);
        }