Ejemplo n.º 1
0
        private void LoadCategory(SingleCategoryViewModel model, string categoryId)
        {
            Category c = MTApp.CatalogServices.Categories.Find(categoryId);

            if (c != null)
            {
                if (c.Bvin != string.Empty)
                {
                    string destination = UrlRewriter.BuildUrlForCategory(new CategorySnapshot(c), MTApp.CurrentRequestContext.RoutingContext);

                    if (c.ImageUrl.StartsWith("~") | c.ImageUrl.StartsWith("http://"))
                    {
                        model.IconUrl = ImageHelper.SafeImage(Url.Content(c.ImageUrl));
                    }
                    else
                    {
                        model.IconUrl = ImageHelper.SafeImage(Url.Content("~/" + c.ImageUrl));
                    }

                    model.LinkUrl = destination;
                    model.AltText = c.MetaTitle;
                    model.Name    = c.Name;

                    if (c.SourceType == CategorySourceType.CustomLink)
                    {
                        model.OpenInNewWindow = c.CustomPageOpenInNewWindow;
                    }
                }
            }
        }
        private void LoadCategory(SingleCategoryViewModel model, string categoryId)
        {
            var c = HccApp.CatalogServices.Categories.Find(categoryId);

            if (c != null)
            {
                var catSnapshot = new CategorySnapshot(c);
                var destination = UrlRewriter.BuildUrlForCategory(catSnapshot);

                var imageUrl = DiskStorage.CategoryIconUrl(HccApp,
                                                           c.Bvin,
                                                           c.ImageUrl,
                                                           Request.IsSecureConnection);
                model.IconUrl = ImageHelper.SafeImage(imageUrl);

                model.LinkUrl       = destination;
                model.AltText       = c.MetaTitle;
                model.Name          = c.Name;
                model.LocalCategory = catSnapshot;

                if (c.SourceType == CategorySourceType.CustomLink)
                {
                    model.OpenInNewWindow = c.CustomPageOpenInNewWindow;
                }
            }
        }
Ejemplo n.º 3
0
        //
        // GET: /ContentBlocks/CategoryRotator/
        public ActionResult Index(ContentBlock block)
        {
            SingleCategoryViewModel model = new SingleCategoryViewModel();

            bool showInOrder = false;

            if (block != null)
            {
                showInOrder = block.BaseSettings.GetBoolSetting("ShowInOrder");

                int nextIndex;
                if (Session[block.Bvin + "NextImageIndex"] != null)
                {
                    nextIndex = (int)Session[block.Bvin + "NextImageIndex"];
                }
                else
                {
                    nextIndex = 0;
                }

                List <ContentBlockSettingListItem> settings = block.Lists.FindList("Categories");

                if (settings.Count != 0)
                {
                    if (settings.Count > nextIndex)
                    {
                        LoadCategory(model, settings[nextIndex].Setting1);
                    }
                    else if (nextIndex >= settings.Count)
                    {
                        if (showInOrder)
                        {
                            nextIndex = 0;
                        }
                        else
                        {
                            nextIndex = MerchantTribe.Web.RandomNumbers.RandomInteger(settings.Count - 1, 0);
                        }
                        LoadCategory(model, settings[nextIndex].Setting1);
                    }

                    if (showInOrder)
                    {
                        nextIndex += 1;
                    }
                    else
                    {
                        nextIndex = MerchantTribe.Web.RandomNumbers.RandomInteger(settings.Count - 1, 0);
                    }
                    Session[block.Bvin + "NextImageIndex"] = nextIndex;
                }
            }

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

            sb.Append("<div class=\"categoryrotator\"><div class=\"decoratedblock\"><div class=\"blockcontent\">");
            sb.Append("<a href=\"" + model.LinkUrl + "\" title=\"" + HttpUtility.HtmlEncode(model.AltText) + "\">");
            sb.Append("<img src=\"" + model.IconUrl + "\" alt=\"" + HttpUtility.HtmlEncode(model.AltText) + "\" /><br />");
            sb.Append("<span>" + HttpUtility.HtmlEncode(model.Name) + "</span></a>");
            sb.Append("</div></div></div>");

            return(sb.ToString());
        }
Ejemplo n.º 5
0
        private List <SingleCategoryViewModel> PrepSubCategories(List <CategorySnapshot> snaps)
        {
            List <SingleCategoryViewModel> result = new List <SingleCategoryViewModel>();

            int columnCount = 1;

            foreach (CategorySnapshot snap in snaps)
            {
                SingleCategoryViewModel model = new SingleCategoryViewModel();

                model.LinkUrl = UrlRewriter.BuildUrlForCategory(snap,
                                                                MTApp.CurrentRequestContext.RoutingContext);
                model.IconUrl = MerchantTribe.Commerce.Storage.DiskStorage.CategoryIconUrl(
                    MTApp,
                    snap.Bvin,
                    snap.ImageUrl,
                    Request.IsSecureConnection);
                model.AltText = snap.Name;
                model.Name    = snap.Name;


                bool isLastInRow  = false;
                bool isFirstInRow = false;
                if ((columnCount == 1))
                {
                    isFirstInRow = true;
                }

                if ((columnCount == 3))
                {
                    isLastInRow = true;
                    columnCount = 1;
                }
                else
                {
                    columnCount += 1;
                }

                model.IsFirstItem = isFirstInRow;
                model.IsLastItem  = isLastInRow;

                result.Add(model);
            }

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

            bool showInOrder = false;

            if (block != null)
            {
                showInOrder = block.BaseSettings.GetBoolSetting("ShowInOrder");

                List <ContentBlockSettingListItem> settings = block.Lists.FindList("Categories");

                int nextIndex = GetProductIndex(settings.Count - 1);

                if (settings.Count != 0)
                {
                    if (settings.Count > nextIndex)
                    {
                        LoadCategory(model, settings[nextIndex].Setting1, app);
                    }
                    else if (nextIndex >= settings.Count)
                    {
                        if (showInOrder)
                        {
                            nextIndex = 0;
                        }
                        else
                        {
                            nextIndex = MerchantTribe.Web.RandomNumbers.RandomInteger(settings.Count - 1, 0);
                        }
                        LoadCategory(model, settings[nextIndex].Setting1, app);
                    }

                    if (showInOrder)
                    {
                        nextIndex += 1;
                    }
                    else
                    {
                        nextIndex = MerchantTribe.Web.RandomNumbers.RandomInteger(settings.Count - 1, 0);
                    }
                }
            }

            return(RenderModel(model));
        }
        private void LoadSubCategories(CategoryPageViewModel model)
        {
            model.SubCategories = new List <SingleCategoryViewModel>();
            var children = HccApp.CatalogServices.Categories.FindVisibleChildren(model.LocalCategory.Bvin);

            foreach (var snap in children)
            {
                var cat = new SingleCategoryViewModel
                {
                    LinkUrl       = UrlRewriter.BuildUrlForCategory(snap),
                    IconUrl       = DiskStorage.CategoryIconUrl(HccApp, snap.Bvin, snap.ImageUrl, Request.IsSecureConnection),
                    AltText       = snap.Name,
                    Name          = snap.Name,
                    LocalCategory = snap
                };

                model.SubCategories.Add(cat);
            }
        }
Ejemplo n.º 8
0
        public ActionResult SingleCategory(int id)
        {
            Category category = db.Categories
                                .SingleOrDefault(c => c.CategoryId == id);

            if (category == null)
            {
                return(HttpNotFound());
            }

            var products = db.Products.ToList()
                           .Where(p => p.CategoryID == category.CategoryId);

            var viewModel = new SingleCategoryViewModel
            {
                Category = category,
                Products = products
            };

            return(View(viewModel));
        }
        public ActionResult Index(ContentBlock block)
        {
            var model = new SingleCategoryViewModel();

            if (block != null)
            {
                var showInOrder = block.BaseSettings.GetBoolSetting("ShowInOrder");
                var settings    = block.Lists.FindList("Categories");

                if (settings.Count != 0)
                {
                    var imageIndex = 0;
                    if (showInOrder)
                    {
                        if (Session[block.Bvin + "PrevImageIndex"] != null)
                        {
                            imageIndex = (int)Session[block.Bvin + "PrevImageIndex"];
                        }
                        imageIndex++;
                        if (imageIndex >= settings.Count)
                        {
                            imageIndex = 0;
                        }

                        Session[block.Bvin + "PrevImageIndex"] = imageIndex;
                    }
                    else
                    {
                        var random = new Random();
                        imageIndex = random.Next(settings.Count);
                    }
                    LoadCategory(model, settings[imageIndex].Setting1);
                }
            }

            return(View(model));
        }