//
        // GET: /ContentBlocks/Top10Products/
        public ActionResult Index(ContentBlock b)
        {
            var profiler = MvcMiniProfiler.MiniProfiler.Current;
            using (profiler.Step("Block:Top10Products"))
            {
                SideMenuViewModel model = new SideMenuViewModel();

                System.DateTime s = new System.DateTime(1900, 1, 1);
                System.DateTime e = new System.DateTime(3000, 12, 31);
                List<Product> products;
                using (profiler.Step("Load top 10 products"))
                {
                    products = MTApp.ReportingTopSellersByDate(s, e, 10);
                }
                using (profiler.Step("Prep Products"))
                {
                    foreach (Product p in products)
                    {
                        SideMenuItem item = new SideMenuItem();
                        item.Title = p.ProductName;
                        item.Name = p.ProductName;
                        item.Url = UrlRewriter.BuildUrlForProduct(p, MTApp.CurrentRequestContext.RoutingContext, string.Empty);
                        item.Name += " - " + p.SitePrice.ToString("C");
                        model.Items.Add(item);
                    }
                }

                model.Title = "Top Sellers";
                return View(model);
            }
        }
        //
        // GET: /ContentBlocks/TopWeeklySellers/
        public ActionResult Index(ContentBlock b)
        {
            SideMenuViewModel model = new SideMenuViewModel();
            model.Title = "Top Weekly Sellers";

            DateTime _StartDate = DateTime.Now;
            DateTime _EndDate = DateTime.Now;
            System.DateTime c = DateTime.Now;
            CalculateDates(c, _StartDate, _EndDate);
            model.Items = LoadProducts(_StartDate, _EndDate);

            return View(model);
        }
        public string Render(MerchantTribe.Commerce.MerchantTribeApplication app, dynamic viewBag, MerchantTribe.Commerce.Content.ContentBlock block)
        {
            SideMenuViewModel model = new SideMenuViewModel();
            model.Title = "Top Weekly Sellers";

            DateTime _StartDate = DateTime.Now;
            DateTime _EndDate = DateTime.Now;
            System.DateTime c = DateTime.Now;
            CalculateDates(c, _StartDate, _EndDate);
            model.Items = LoadProducts(app, _StartDate, _EndDate);

            model.Title = "Top Sellers";

            return RenderModel(model);
        }
        //
        // GET: /ContentBlocks/TopWeeklySellers/
        public ActionResult Index(ContentBlock b)
        {
            var profiler = MvcMiniProfiler.MiniProfiler.Current;
            using (profiler.Step("Block:TopWeeklySellers"))
            {
                SideMenuViewModel model = new SideMenuViewModel();
                model.Title = "Top Weekly Sellers";

                DateTime _StartDate = DateTime.Now;
                DateTime _EndDate = DateTime.Now;
                System.DateTime c = DateTime.Now;
                CalculateDates(c, _StartDate, _EndDate);
                model.Items = LoadProducts(_StartDate, _EndDate);

                return View(model);
            }
        }
        public string RenderModel(SideMenuViewModel model)
        {
            StringBuilder sb = new StringBuilder();

            sb.Append("<div class=\"sidemenu topsellers\">");
            sb.Append("<div class=\"decoratedblock\">");
            sb.Append("<h3>" + HttpUtility.HtmlEncode(model.Title) + "</h3>");  
            sb.Append("<ol>");
            foreach (var item in model.Items)
            {
            sb.Append("<li><a href=\"" + item.Url + "\" title=\"" + HttpUtility.HtmlEncode(item.Title) + "\">" + HttpUtility.HtmlEncode(item.Name) + "</a></li>");
            }
            sb.Append("</ol>");
            sb.Append("</div>");
            sb.Append("</div>");  

            return sb.ToString();
        }
        //
        // GET: /ContentBlocks/SideMenu/
        public ActionResult Index(ContentBlock block)
        {
            SideMenuViewModel model = new SideMenuViewModel();

            if (block != null)
            {
                model.Title = block.BaseSettings.GetSettingOrEmpty("Title");

                List<ContentBlockSettingListItem> links = block.Lists.FindList("Links");
                if (links != null)
                {
                    foreach (ContentBlockSettingListItem l in links)
                    {
                        model.Items.Add(AddSingleLink(l));
                    }
                }
            }

            return View(model);
        }
        public string Render(MerchantTribe.Commerce.MerchantTribeApplication app, dynamic viewBag, MerchantTribe.Commerce.Content.ContentBlock block)
        {
            SideMenuViewModel model = new SideMenuViewModel();

            if (block != null)
            {
                model.Title = block.BaseSettings.GetSettingOrEmpty("Title");

                List<ContentBlockSettingListItem> links = block.Lists.FindList("Links");
                if (links != null)
                {
                    foreach (ContentBlockSettingListItem l in links)
                    {
                        model.Items.Add(AddSingleLink(l));
                    }
                }
            }

            return RenderModel(model);
        }
        public string Render(MerchantTribe.Commerce.MerchantTribeApplication app, dynamic viewBag, MerchantTribe.Commerce.Content.ContentBlock block)
        {
            SideMenuViewModel model = new SideMenuViewModel();

            System.DateTime s = new System.DateTime(1900, 1, 1);
            System.DateTime e = new System.DateTime(3000, 12, 31);
            List<Product> products;
            products = app.ReportingTopSellersByDate(s, e, 10);
            foreach (Product p in products)
            {
                SideMenuItem item = new SideMenuItem();
                item.Title = p.ProductName;
                item.Name = p.ProductName;
                item.Url = UrlRewriter.BuildUrlForProduct(p, app.CurrentRequestContext.RoutingContext, string.Empty);
                item.Name += " - " + p.SitePrice.ToString("C");
                model.Items.Add(item);
            }

            model.Title = "Top Sellers";

            return RenderModel(model);      
        }
        public string RenderModel(SideMenuViewModel model)
        {
            StringBuilder sb = new StringBuilder();

            sb.Append("<div class=\"sidemenu\">");
            sb.Append("<div class=\"decoratedblock\">");
            sb.Append("<h4>" + HttpUtility.HtmlEncode(model.Title) + "</h4>");
            sb.Append("<ul>");
            foreach (var item in model.Items)
            {
                sb.Append("<li><a href=\"" + item.Url + "\" class=\"" + HttpUtility.HtmlEncode(item.CssClass) + "\" title=\"" + HttpUtility.HtmlEncode(item.Title));
                if (item.OpenInNewWindow == true)
                {
                    sb.Append(" target=\"_blank\"");
                }
                sb.Append("\">" + HttpUtility.HtmlEncode(item.Name) + "</a></li>");
            }
            sb.Append("</ul>");
            sb.Append("</div>");
            sb.Append("</div>");
                               
            return sb.ToString();
        }