// method that saves the edited changes in a tag public void EditTag(Tag tag) { context.Tags.Attach(tag); // add category to queue context.Entry(tag).State = EntityState.Modified; // makes category's state set to modified context.SaveChanges(); // save changes in queue }
// returns the Id of the added tag public int AddTag(Tag tag) { context.Tags.Add(tag); // adds category to queue context.SaveChanges(); // saves changes in queue. return tag.TagId; }
public ContentResult EditTag(Tag tag) { string json; //variable for passing successful or unsuccessful json data ModelState.Clear(); //remove items from the model state dictionary // if the current category is valid if (TryValidateModel(tag)) { blogRepository.EditTag(tag); // get id from newly edited tag and attempt to save data // if id equals the edited category id, category addition was successful json = JsonConvert.SerializeObject(new { id = tag.TagId, success = true, message = "Changes saved successfully." }); } //else if the id = 0, the edit failed else { json = JsonConvert.SerializeObject(new { id = 0, success = false, message = "Failed to save the changes." }); } return Content(json, "application/json"); // send results to the user for display }