public JsonResult CreateUserTag(string spaceKey) { bool isBanned = false; string tagName = Request.Form["TagName"]; tagName = TextFilter(tagName, out isBanned); if (isBanned) { WebUtility.SetStatusCodeForError(Response); return Json(new StatusMessageData(StatusMessageType.Error, "内容中包含非法词语!")); } long userId = UserIdToUserNameDictionary.GetUserId(spaceKey); TagService tagService = new TagService(TenantTypeIds.Instance().User()); int count = userProfileSettings.MaxPersonTag; if (tagService.GetItemInTagsOfItem(userId).Count() >= count) { WebUtility.SetStatusCodeForError(Response); return Json(new StatusMessageData(StatusMessageType.Error, "最多只能添加" + count + "个标签!")); } if (tagName != null) { tagService.AddTagToItem(tagName, userId, userId); return Json(new StatusMessageData(StatusMessageType.Success, "创建成功")); } WebUtility.SetStatusCodeForError(Response); return Json(new StatusMessageData(StatusMessageType.Error, "标签不能为空!")); }
/// <summary> /// 创建关联个人标签 /// </summary> /// <param name="spaceKey">用户spaceKey</param> public ActionResult AddTagToItem(string spaceKey, string tagName) { long userId = UserIdToUserNameDictionary.GetUserId(spaceKey); if (tagName != null) { TagService tagService = new TagService(TenantTypeIds.Instance().User()); tagService.AddTagToItem(tagName, userId, userId); } return RedirectToAction("_ListMyUserTags", new { spaceKey = spaceKey, l = DateTime.UtcNow.Millisecond }); }