Example #1
0
        public static MvcHtmlString ArticleLink(this HtmlHelper helper, DIYFE.EF.Article article)
        {
            //NOTE: THERE IS A BETTER WAY TO DO THIS...I'M BUSY...SORRY\
            //THE Exception GENERATED IS MOST LIKELY TO BE BECUASE THE Article didn't load it's Category
            //sooooo catch the exception and load it from cache
            try
            {
                if (article.Category == null)
                { }
            }
            catch (Exception ex)
            {
                article.Category = AppStatic.Categories.Where(c => c.CategoryRowId == article.CategoryRowId).FirstOrDefault();
            }

            //the article type is required to build the URL, not bothered by loading it or checking for it...could probably use a enum
            string articleType = "";
            switch (article.ArticleTypeId)
            {
                case 1:
                    articleType = "post/";
                    break;
                case 2:
                    articleType = "project/";
                    break;
                case 3:
                    articleType = "blog/";
                    break;
                case 4:
                    articleType = "news/";
                    break;
                default:
                    articleType = "home/";
                    break;
            }

            string ahref = "<a href=\"" + AppStatic.BaseSiteUrl + articleType + article.Category.CategoryUrl + "/";

            //MvcHtmlString ahref = new MvcHtmlString("<a href=\"" + AppStatic.BaseSiteUrl + article.Category.CategoryUrl + "/");
            if (!String.IsNullOrEmpty(article.Category.SecondLevCategoryUrl))
            {
                ahref += article.Category.SecondLevCategoryUrl + "/";
            }
            if (!String.IsNullOrEmpty(article.Category.ThirdLevCategoryUrl))
            {
                ahref += article.Category.ThirdLevCategoryUrl + "/";
            }
            ahref += article.URLLink + "\">" + article.Name + "</a>";
            // AppStatic.BaseSiteUrl + linkPrefix + "/" + cat.CategoryUrl,
            return new MvcHtmlString(ahref);
        }
Example #2
0
        //public static List<CustomHtmlLink> GenerateCrumbLinks(string Url)
        //{
        //    List<CustomHtmlLink> linkList = new List<CustomHtmlLink>();
        //    return linkList;
        //}
        public static List<CustomHtmlLink> GenerateCrumbLinks(DIYFE.EF.Category cat, string linkPrefix)
        {
            List<CustomHtmlLink> linkList = new List<CustomHtmlLink>();
            //Category cat = AppStatic.Categories
            //                    .Where(c => c.CategoryRowId == categoryRowId)
            //                    .FirstOrDefault();
            CustomHtmlLink rootLink = new CustomHtmlLink();
            rootLink.LinkText = System.Globalization.CultureInfo.CurrentUICulture.TextInfo.ToTitleCase(linkPrefix) + "s";
            rootLink.Href = AppStatic.BaseSiteUrl + linkPrefix + "/";
            rootLink.Title = "Base diyfe categor";
            linkList.Add(rootLink);

            if (cat != null)
            {
                if (!String.IsNullOrEmpty(cat.CategoryUrl))
                {
                    CustomHtmlLink link = new CustomHtmlLink();
                    link.LinkText = cat.CategoryName;
                    link.Href = AppStatic.BaseSiteUrl + linkPrefix + "/" + cat.CategoryUrl;
                    link.Title = cat.CategoryName;
                    linkList.Add(link);
                }
                if (!String.IsNullOrEmpty(cat.SecondLevCategoryUrl))
                {
                    CustomHtmlLink link = new CustomHtmlLink();
                    link.LinkText = cat.SecondLevCategoryName;
                    link.Href = "/" + linkPrefix + "/" + cat.CategoryUrl + "/" + cat.SecondLevCategoryUrl;
                    link.Title = cat.SecondLevCategoryName;
                    linkList.Add(link);
                }
                if (!String.IsNullOrEmpty(cat.ThirdLevCategoryUrl))
                {
                    CustomHtmlLink link = new CustomHtmlLink();
                    link.LinkText = cat.ThirdLevCategoryName;
                    link.Href = "/" + linkPrefix + "/" + cat.CategoryUrl + "/" + cat.SecondLevCategoryUrl + "/" + cat.ThirdLevCategoryUrl;
                    link.Title = cat.ThirdLevCategoryName;
                    linkList.Add(link);
                }
            }
            else
            {
                throw (new Exception("Generate Crumb Links - - -  Unable to find correct category."));
            }

            return linkList;
        }
Example #3
0
        public ActionResult AddCategory(DIYFE.EF.Category category)
        {
            var data = new object();

            using (var db = new DIYFE.EF.DIYFEEntities())
            {
                if (category.ThirdLevCategoryId == 0 && category.SecondLevCategoryId != 0)
                {
                    category.ThirdLevCategoryId = db.Categories.Max(c => c.ThirdLevCategoryId).Value;
                }
                if (category.SecondLevCategoryId == 0)
                {
                    category.SecondLevCategoryId = db.Categories.Max(c => c.SecondLevCategoryId).Value;
                }
                if (category.CategoryId == 0)
                {
                    category.CategoryId = db.Categories.Max(c => c.CategoryId);
                }
                db.Categories.Add(category);
                db.SaveChanges();
                data = new { success = true };
                //allCats = db.Categories.ToList();
            }

            AppStatic.LoadStaticCache();

            //Category cat = new Category();
            //if (cat.InsertCategory(category))
            //{
            //    AppStatic.LoadStaticCache();
            //    data = new { success = true };
            //}
            //else
            //{
            //    data = new { success = false, message = "Failed to insert new category." };
            //    return Json(data);
            //}

            return Json(data);
        }
Example #4
0
        public static MvcHtmlString ArticleLink(this HtmlHelper helper, DIYFE.EF.Article article, string styleClass, string linkText)
        {
            //NOTE: THERE IS A BETTER WAY TO DO THIS...I'M BUSY...SORRY
            try
            {
                if (article.Category == null)
                { }
            }
            catch (Exception ex)
            {
                using (var db = new DIYFE.EF.DIYFEEntities())
                {
                    article.Category = db.Categories.Where(c => c.CategoryRowId == article.CategoryRowId).FirstOrDefault();
                }
            }

            //TODO:the article type is required to build the URL, not bothered by loading it or checking for it...could probably use a enum
            string articleType = "";
            switch (article.ArticleTypeId)
            {
                case 1:
                    articleType = "post/";
                    break;
                case 2:
                    articleType = "project/";
                    break;
                case 3:
                    articleType = "blog/";
                    break;
                case 4:
                    articleType = "news/";
                    break;
                default:
                    articleType = "home/";
                    break;
            }

            string ahref = "<a class=\"" + styleClass + "\" href=\"" + AppStatic.BaseSiteUrl + articleType + article.Category.CategoryUrl + "/";

            //MvcHtmlString ahref = new MvcHtmlString("<a href=\"" + AppStatic.BaseSiteUrl + article.Category.CategoryUrl + "/");
            if (!String.IsNullOrEmpty(article.Category.SecondLevCategoryUrl))
            {
                ahref += article.Category.SecondLevCategoryUrl + "/";
            }
            if (!String.IsNullOrEmpty(article.Category.ThirdLevCategoryUrl))
            {
                ahref += article.Category.ThirdLevCategoryUrl + "/";
            }
            ahref += article.URLLink + "\">" + linkText + "</a>";
            // AppStatic.BaseSiteUrl + linkPrefix + "/" + cat.CategoryUrl,
            return new MvcHtmlString(ahref);
        }
Example #5
0
        public static List<CustomHtmlLink> GenerateCrumbLinks(DIYFE.EF.Category cat, string linkPrefix)
        {
            List<CustomHtmlLink> linkList = new List<CustomHtmlLink>();
            //Category cat = AppStatic.Categories
            //                    .Where(c => c.CategoryRowId == categoryRowId)
            //                    .FirstOrDefault();
            CustomHtmlLink rootLink = new CustomHtmlLink();
            rootLink.LinkText = System.Globalization.CultureInfo.CurrentUICulture.TextInfo.ToTitleCase(linkPrefix) + "s";
            rootLink.Href = StaticConfig.BaseSiteUrl + linkPrefix + "/";
            rootLink.Title = linkPrefix;
            linkList.Add(rootLink);

            if (cat != null)
            {
                if (!String.IsNullOrEmpty(cat.CategoryUrl))
                {
                    CustomHtmlLink link = new CustomHtmlLink();
                    link.LinkText = cat.CategoryName;
                    link.Href = StaticConfig.BaseSiteUrl + linkPrefix + "/" + cat.CategoryUrl;
                    link.Title = cat.CategoryName;
                    linkList.Add(link);
                }
                if (!String.IsNullOrEmpty(cat.SecondLevCategoryUrl))
                {
                    CustomHtmlLink link = new CustomHtmlLink();
                    link.LinkText = cat.SecondLevCategoryName;
                    link.Href = "/" + linkPrefix + "/" + cat.CategoryUrl + "/" + cat.SecondLevCategoryUrl;
                    link.Title = cat.SecondLevCategoryName;
                    linkList.Add(link);
                }
                if (!String.IsNullOrEmpty(cat.ThirdLevCategoryUrl))
                {
                    CustomHtmlLink link = new CustomHtmlLink();
                    link.LinkText = cat.ThirdLevCategoryName;
                    link.Href = "/" + linkPrefix + "/" + cat.CategoryUrl + "/" + cat.SecondLevCategoryUrl + "/" + cat.ThirdLevCategoryUrl;
                    link.Title = cat.ThirdLevCategoryName;
                    linkList.Add(link);
                }
            }

            //CustomHtmlLink link2 = new CustomHtmlLink();
            //link2.LinkText = "Bread Crumb Links";
            //link2.Href = "/" + linkPrefix;
            //linkList.Add(link2);

            return linkList;
        }