public int AddTag(Tag tag) { if (_context.Entry(tag).State == EntityState.Detached) { _context.Tags.Attach(tag); } _context.Tags.Add(tag); _context.SaveChanges(); return tag.Id; }
public static MvcHtmlString TagLink(this HtmlHelper helper, Tag tag) { return helper.ActionLink( tag.Name, "Tag", "Blog", new {tag = tag.UrlSlug}, new { title = String.Format("See all posts that mention {0}.", tag.Name), @class = "tagLink" }); }
public void EditTag(Tag tag) { DbEntityEntry<Tag> entry = _context.Entry(tag); if (entry.State == EntityState.Detached) { DbSet set = _context.Set(tag.GetType()); var attachedEntity = (Tag) set.Find(tag.Id); if (attachedEntity != null) { DbEntityEntry<Tag> attachedEntry = _context.Entry(attachedEntity); attachedEntry.CurrentValues.SetValues(tag); } } else { entry.State = EntityState.Modified; } _context.SaveChanges(); }
public ContentResult EditTag(Tag tag) { string json; if (ModelState.IsValid){ _blogRepository.EditTag(tag); json = JsonConvert.SerializeObject(new { id = tag.Id, success = true, message = "Changes saved successfully." }); } else{ json = JsonConvert.SerializeObject(new { id = 0, success = false, message = "Failed to save the changes." }); } return Content(json, "application/json"); }