private void AddWorks(Category category, string categoryPath) { var works = new List<Work>(); foreach (string workPath in Directory.EnumerateDirectories(categoryPath)) { var workDir = new DirectoryInfo(workPath); var work = new Work(); work.Name = workDir.Name; var pics = new List<string>(); work.Pictures = pics; foreach (string pic in GetFiles(workPath, @"\.jpg|\.gif|\.png|\.jpeg")) { string picPath = pic.Replace(HttpRuntime.AppDomainAppPath, "/").Replace(Path.DirectorySeparatorChar, '/'); pics.Add(picPath); } var textFile = GetFiles(workPath, @"\.txt").FirstOrDefault(); if (textFile != null) { work.Description = File.ReadAllText(textFile);//.Replace(Environment.NewLine, "<br>"); } work.Category = category; works.Add(work); } category.Works = works; }
public static MvcHtmlString WorkMenuItem(this HtmlHelper html, Category category, string actionName, string controllerName) { var header = new TagBuilder("span"); if (category.IsSelected) { header.MergeAttribute("class", "categoryHeader selected"); } else { header.MergeAttribute("class", "categoryHeader"); } var headerLink = new TagBuilder("a"); headerLink.MergeAttribute("href", "#" + category.Name); headerLink.InnerHtml = category.Name; header.InnerHtml = headerLink.ToString(); var workList = new TagBuilder("ul"); foreach (var work in category.Works) { var workItem = new TagBuilder("li"); if(work.IsSelected) { workItem.MergeAttribute("class", "selected"); } workItem.InnerHtml = html.ActionLink(work.Name, actionName, controllerName, new { id = work.Name }, null).ToHtmlString(); workList.InnerHtml += workItem.ToString(); } return new MvcHtmlString(header.ToString() + workList.ToString()); }
private IEnumerable<Category> FindAllWorks() { var directories = Directory.EnumerateDirectories(PortfolioRoot) .Select(d => new { Order = d.EndsWith("other") ? 1 : 0, d }) .OrderBy(x => x.Order).Select(x => x.d); foreach (string categoryPath in directories) { var categoryDir = new DirectoryInfo(categoryPath); var catagory = new Category(); catagory.Name = categoryDir.Name; AddWorks(catagory, categoryPath); yield return catagory; } }