public ActionResult Edit(int?id) { if (!isAdmin) { return(RedirectToAction("Index", "Home")); } PortfolioPost post = GetPost(id); StringBuilder tagList = new StringBuilder(); foreach (PortfolioTag tag in post.PortfolioTags) { tagList.AppendFormat("{0} ", tag.Name); } StringBuilder fileList = new StringBuilder(); foreach (PortfolioFile file in post.PortfolioFiles) { fileList.AppendFormat("{0} ", file.Name); } StringBuilder linkList = new StringBuilder(); foreach (PortfolioLink link in post.PortfolioLinks) { linkList.AppendFormat("{0} ", link.Name); } ViewBag.Tags = tagList.ToString(); ViewBag.Links = linkList.ToString(); ViewBag.Files = fileList.ToString(); return(View(post)); }
public ActionResult Delete(int id) { if (isAdmin) { PortfolioPost p = GetPost(id); model.DeleteObject(p); model.SaveChanges(); } return(RedirectToAction("index")); }
public ActionResult Details(int id) { PortfolioPost posts = ( from post in model.PortfolioPosts where post.ID == id orderby post.DateTime descending select post ).FirstOrDefault(); ViewBag.IsAdmin = isAdmin; return(View(posts)); }
public ActionResult Update(int?id, int ProjTypeID, string title, string body, DateTime dateTime, string tags, string files, string filesURL, string links, string linksURL) { if (!isAdmin) { return(RedirectToAction("Index")); } PortfolioPost post = GetPost(id); post.ProjTypeID = ProjTypeID; post.Title = title; post.Body = body; post.DateTime = dateTime; post.PortfolioTags.Clear(); tags = tags ?? string.Empty; string[] tagNames = tags.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); foreach (string tagName in tagNames) { post.PortfolioTags.Add(GetTag(tagName)); } files = files ?? string.Empty; string[] fileNames = files.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); string[] fileURLs = filesURL.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); for (int i = 0; i < fileNames.Count(); i++) { post.PortfolioFiles.Add(GetFile(fileNames[i], fileURLs[i])); } links = links ?? string.Empty; string[] linkNames = links.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); string[] linkURLs = linksURL.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); for (int i = 0; i < linkNames.Count(); i++) { post.PortfolioLinks.Add(GetLink(linkNames[i], linkURLs[i])); } if (!id.HasValue) { model.AddToPortfolioPosts(post); } model.SaveChanges(); return(RedirectToAction("Details", new { id = post.ID })); }