public ActionResult Create(Blog blog, string[] Cat, string BlogTags) { if (ModelState.IsValid) { string[] blogtags = BlogTags.Split(','); string[] tags = (from p in db.Tags select p.Name).ToArray(); string[] differenceQuery = blogtags.Except(tags).ToArray(); foreach(string t in differenceQuery) { Tag tempTag = new Tag(); tempTag.Id = 0; tempTag.Name = t.TrimStart().TrimEnd(); tempTag.Blogs= null; db.Tags.Add(tempTag); db.SaveChanges(); } blog.Tags = (from p in db.Tags where blogtags.Contains(p.Name) select p).ToList(); blog.Categories = (from p in db.Categorys where Cat.Contains(p.Name) select p).ToList(); db.Blogs.Add(blog); db.SaveChanges(); return RedirectToAction("Index"); } return View(); }
public ActionResult Create(Tag tag) { if (ModelState.IsValid) { db.Tags.Add(tag); db.SaveChanges(); return RedirectToAction("Index"); } return View(tag); }
public ActionResult Edit(Tag tag) { if (ModelState.IsValid) { db.Entry(tag).State = EntityState.Modified; db.SaveChanges(); return RedirectToAction("Index"); } return View(tag); }