public JsonResult AddToDefinition(string tagName, int definitionId) { var ajaxResponse = new Dictionary <string, string>(); ajaxResponse["actionType"] = "create"; int tagId = AddTagToDataBase(tagName); var relation = _db.DefTagRelations.FirstOrDefault( x => x.DefinitionID == definitionId && x.TagID == tagId); if (relation != null) { ajaxResponse["doExist"] = "true"; } else { ajaxResponse["doExist"] = "false"; relation = new DefTagRelation { DefinitionID = definitionId, TagID = tagId, }; _db.DefTagRelations.AddObject(relation); _db.SaveChanges(); } ajaxResponse["id"] = tagId.ToString(CultureInfo.InvariantCulture); ajaxResponse["message"] = "Тэг успешно добавлен"; ajaxResponse["success"] = "true"; ajaxResponse["body"] = tagName; return(Json(ajaxResponse, JsonRequestBehavior.AllowGet)); }
/// <summary> /// Deletes DefTagRelation from database /// </summary> /// <param name="relation"></param> private void RemoveDefFromDataBase(DefTagRelation relation) { _db.DefTagRelations.DeleteObject(relation); _db.SaveChanges(); }