public async Task<object> Post(string tagName, string tagColor,string type, string data, string isFocus,string isShowToLinkers) { var sharelinkTagService = this.UseSharelinkTagService().GetSharelinkTagService(); var shareService = this.UseShareService().GetShareService(); var userService = this.UseSharelinkerService().GetSharelinkerService(); var userId = new ObjectId(UserSessionData.UserId); bool focus = false; bool showToLinker = false; try { focus = bool.Parse(isFocus); } catch (Exception) { } try { showToLinker = bool.Parse(isShowToLinkers); } catch (Exception) { } var newTag = new SharelinkTag() { TagColor = tagColor, TagName = tagName, TagDomain = SharelinkTagConstant.TAG_DOMAIN_CUSTOM, TagType = type, Data = data, IsFocus = focus, UserId = userId, CreateTime = DateTime.UtcNow, ShowToLinkers = showToLinker }; var r = await sharelinkTagService.CreateNewSharelinkTag(newTag); if (showToLinker && newTag.IsSharelinkerTag() == false) { if (Startup.HotThemes.Contains(tagName) == false) { Startup.HotThemes.Add(tagName); } await SendShowToLinkerTagMessage(shareService, userService, userId, r); } return SharelinkTagToResultObject(r.Id.ToString(),r); }
private static object SharelinkTagToResultObject(string tagId,SharelinkTag r) { return new { tagId = tagId, tagName = r.TagName, tagColor = r.TagColor, data = r.Data, isFocus = r.IsFocus.ToString().ToLower(), domain = r.TagDomain, type = r.TagType, showToLinkers = r.ShowToLinkers.ToString().ToLower(), time = DateTimeUtil.ToAccurateDateTimeString(r.CreateTime) }; }
private async Task SendShowToLinkerTagMessage(ShareService shareService, SharelinkerService userService, ObjectId userId, SharelinkTag newTag) { var newShare = new ShareThing() { ShareTime = DateTime.UtcNow, ShareType = newTag.IsFocus ? ShareThingConstants.SHARE_TYPE_MESSAGE_FOCUS_TAG : ShareThingConstants.SHARE_TYPE_MESSAGE_ADD_TAG, UserId = userId, ShareContent = SharelinkTagToResultObject(newTag.Id.ToString(),newTag).ToJson() }; await shareService.PostNewShareThing(newShare); var linkers = await userService.GetUserlinksOfUserId(UserSessionData.UserId); var linkerIds = from l in linkers select l.SlaveUserObjectId; var newMails = new List<ShareThingMail>(); foreach (var linker in linkerIds) { if (!Startup.SharelinkCenterList.Contains(linker.ToString())) { var newMail = new ShareThingMail() { ShareId = newShare.Id, Time = DateTime.UtcNow, ToSharelinker = linker }; newMails.Add(newMail); } } shareService.InsertMails(newMails); Startup.ServicesProvider.GetBahamutPubSubService().PublishShareMessages(newMails); }
public static SharelinkTag GeneratePersonTag(string tagDomain, string userId) { var tag = new SharelinkTag() { Data = userId, TagDomain = tagDomain, TagType = SharelinkTagConstant.TAG_TYPE_SHARELINKER, TagColor = "#438ccb", IsFocus = true, Id = new ObjectId(userId), UserId = new ObjectId(userId), ShowToLinkers = true, TagName = "Me" }; return tag; }
public async Task<SharelinkTag> CreateNewSharelinkTag(SharelinkTag newTag) { var collection = Client.GetDatabase("Sharelink").GetCollection<Sharelinker>("Sharelinker"); var collectionTag = Client.GetDatabase("Sharelink").GetCollection<SharelinkTag>("SharelinkTag"); await collectionTag.InsertOneAsync(newTag); var res = await collection.UpdateOneAsync(u => u.Id == newTag.UserId, new UpdateDefinitionBuilder<Sharelinker>().Push(su => su.SharelinkTags, newTag.Id)); return newTag; }
public static bool IsTagMatch(this SharelinkTag tag1,SharelinkTag tag2) { return tag1.Data == tag2.Data; }