public MakerReturn Post() { MakerReturn r = new MakerReturn(); #region look for duplicate Query qDup = new Query(); qDup.TopRecords = 1; qDup.Columns = new ColumnSet(Bobs.Comment.Columns.K, Bobs.Comment.Columns.ThreadK); qDup.QueryCondition = new Q(Bobs.Comment.Columns.DuplicateGuid, (Guid)DuplicateGuid); CommentSet csDup = new CommentSet(qDup); if (csDup.Count > 0) { r.Success = false; r.MessageHtml = "Duplicate thread detected"; r.Thread = csDup[0].Thread; r.Duplicate = true; return r; } #endregion #region ensure two parents are different types... if (ParentType.Equals(Model.Entities.ObjectType.Group) && GroupK != ParentK) { r.Success = false; r.MessageHtml = "Posting to group, but GroupK!=ParentK"; return r; } #endregion #region Make sure Group and ParentType are syncronised if (GroupK > 0 && ParentType.Equals(Model.Entities.ObjectType.None)) { ParentType = Model.Entities.ObjectType.Group; ParentK = GroupK; } if (GroupK == 0 && ParentType.Equals(Model.Entities.ObjectType.Group)) { GroupK = ParentK; } #endregion #region if we're posting in a group, make sure we are a member if (GroupK > 0) { GroupUsr gu = ParentGroup.GetGroupUsr(PostingUsr); if (!PostingUsr.CanGroupMember(gu)) { r.Success = false; r.MessageHtml = "You have tried to post a message in the " + ParentGroup.Link() + " group, but you're not currently a member of this group. Check out the group homepage for more information."; return r; } } #endregion #region ensure both parents map to real objects if (!ParentType.Equals(Model.Entities.ObjectType.None)) { if (ParentBob == null) { r.Success = false; r.MessageHtml = "You've tried to post a message in a non-existant chat. Maybe it's been deleted."; return r; } } if (GroupK > 0) { if (ParentGroup == null) { r.Success = false; r.MessageHtml = "You've tried to post a message in a non-existant group. Maybe it's been deleted."; return r; } } #endregion #region Private bool tPrivate = false; bool gPrivate = false; if (Private) { if (GroupK == 0) tPrivate = true; else gPrivate = true; } #endregion #region News tNews = false; tNewsStatus = NewsStatusEnum.None; int tNewsLevel = 0; int tNewsUsrK = 0; int tNewsModeratorUsrK = 0; if (News) { if (tPrivate) { r.Success = false; r.MessageHtml = "You've tried to post private news! How did this happen?"; return r; } else if (GroupK == 0) { r.Success = false; r.MessageHtml = "You've tried to post public non-group news. How did this happen?"; return r; //if (PostingUsr.NewsPermissionLevel >= 10 || PostingUsr.IsSuper) //{ // tNews = true; // tNewsStatus = NewsStatusEnum.Recommended; // tNewsModeratorUsrK = Usr.GetNewsModeratorUsrK(); // tNewsLevel = 10; // tNewsUsrK = PostingUsr.K; //} //else //{ // tNews = false; // tNewsStatus = NewsStatusEnum.Recommended; // tNewsModeratorUsrK = Usr.GetNewsModeratorUsrK(); // tNewsLevel = 0; // tNewsUsrK = PostingUsr.K; //} } else { GroupUsr gu = ParentGroup.GetGroupUsr(PostingUsr); if (PostingUsr.CanGroupNewsAdmin(gu)) { tNews = true; tNewsStatus = NewsStatusEnum.Done; tNewsLevel = 10; tNewsUsrK = PostingUsr.K; } else { tNews = false; tNewsStatus = NewsStatusEnum.Recommended; tNewsLevel = 10; tNewsUsrK = PostingUsr.K; } } } #endregion #region Sealed bool tSealed = false; if (Sealed) { if (tPrivate) tSealed = true; } #endregion #region Closed bool tClosed = false; if (Closed) { tClosed = true; } #endregion #region Review bool tReview = false; if (Review) { if (ParentType.Equals(Model.Entities.ObjectType.Event) && GroupK == 0) { Query qReviews = new Query(); qReviews.QueryCondition = new And( new Q(Columns.UsrK, PostingUsr.K), new Q(Columns.ParentObjectType, Model.Entities.ObjectType.Event), new Q(Columns.ParentObjectK, ParentK), new Q(Columns.IsReview, true) ); qReviews.TopRecords = 1; qReviews.Columns = new ColumnSet(Thread.Columns.K); ThreadSet tsReviews = new ThreadSet(qReviews); if (tsReviews.Count > 0) { r.Success = false; r.MessageHtml = "You've already posted a review. You can only post one review per event."; r.Duplicate = true; r.Thread = tsReviews[0]; return r; } else tReview = true; } else { r.Success = false; r.MessageHtml = "You must post a review in an event chat board."; return r; } } #endregion if (GroupK > 0) CurrentGroupUsr = ParentGroup.GetGroupUsr(PostingUsr); Transaction trans = null;//new Transaction(); NewThread = new Thread(); try { #region Create thread NewThread.DateTime = DateTime.Now; NewThread.Enabled = true; NewThread.UsrK = PostingUsr.K; NewThread.LastPostUsrK = PostingUsr.K; NewThread.Subject = Helpers.Strip(Subject, true, true, true, true); NewThread.ParentObjectType = ParentType; NewThread.ParentObjectK = ParentK; if (GroupK > 0) NewThread.GroupK = ParentGroup.K; else NewThread.GroupK = 0; NewThread.Private = tPrivate; NewThread.GroupPrivate = gPrivate; if (GroupK > 0) NewThread.PrivateGroup = ParentGroup.PrivateChat; else NewThread.PrivateGroup = false; NewThread.IsNews = tNews; NewThread.NewsStatus = tNewsStatus; NewThread.NewsLevel = tNewsLevel; NewThread.NewsModeratorUsrK = tNewsModeratorUsrK; NewThread.NewsUsrK = tNewsUsrK; NewThread.Sealed = tSealed; NewThread.Closed = tClosed; NewThread.IsReview = tReview; NewThread.UpdateAncestorLinksNoUpdate(); NewThread.Update(trans); #endregion #region Add PostingUsr ThreadUsr CurrentThreadUsr = new ThreadUsr(); CurrentThreadUsr.DateTime = DateTime.Now; CurrentThreadUsr.InvitingUsrK = PostingUsr.K; CurrentThreadUsr.UsrK = PostingUsr.K; CurrentThreadUsr.ThreadK = NewThread.K; CurrentThreadUsr.ChangeStatus(ThreadUsr.StatusEnum.Archived, NewThread.DateTime); CurrentThreadUsr.StatusChangeObjectK = PostingUsr.K; CurrentThreadUsr.StatusChangeObjectType = Model.Entities.ObjectType.Usr; CurrentThreadUsr.Update(trans); #endregion #region Make the comment Comment.Maker cMaker = new Comment.Maker(); cMaker.Body = Body; cMaker.ParentThread = NewThread; cMaker.DuplicateGuid = DuplicateGuid; cMaker.PostingUsr = PostingUsr; cMaker.InviteKs = InviteKs; cMaker.AlertedUsrs = AlertedUsrs; cMaker.NewThread = true; cMaker.CurrentThreadUsr = CurrentThreadUsr; cMaker.CurrentGroupUsr = CurrentGroupUsr; cMaker.RunAsync = RunAsync; cMaker.DisableLiveChatMessage = DisableLiveChatMessage; Comment.MakerReturn cReturn = null; try { cReturn = cMaker.Post(trans); } catch (Exception ex) { NewThread.DeleteAll(null); throw ex; } #endregion //SendThreadAlertsJob sendThreadsAlert = new SendThreadAlertsJob(NewThread.K, AlertedUsrs, PostingUsr.K, Subject, InviteKs); //if (this.RunAsync) //{ // sendThreadsAlert.ExecuteAsynchronously(); //} //else //{ // sendThreadsAlert.ExecuteSynchronously(); //} r.Success = true; r.Thread = NewThread; r.Comment = cReturn.Comment; return r; } catch (Exception ex) { //trans.Rollback(); NewThread.DeleteAll(null); throw ex; } finally { //trans.Close(); } }
public void SendMatchNotification() { #region Init thread Thread t = new Thread(); t.DateTime = DateTime.Now; t.Enabled = true; t.ParentObjectK = 0; t.ParentObjectType = Model.Entities.ObjectType.None; t.Subject = "DSI Date introduction - " + this.Usr.NickName + " and " + this.DateUsr.NickName; t.UsrK = this.UsrK; t.Private = true; t.IsNews = false; t.IsSticky = false; t.Update(); t.UpdateAncestorLinks(null); ThreadUsr tu = new ThreadUsr(); tu.DateTime = DateTime.Now; tu.InvitingUsrK = this.UsrK; tu.UsrK = this.DateUsrK; tu.ThreadK = t.K; tu.ChangeStatus(ThreadUsr.StatusEnum.NewInvite); tu.StatusChangeObjectK = this.UsrK; tu.StatusChangeObjectType = Model.Entities.ObjectType.Usr; tu.PrivateChatType = ThreadUsr.PrivateChatTypes.Popup; tu.Update(); ThreadUsr tu1 = new ThreadUsr(); tu1.DateTime = DateTime.Now; tu1.InvitingUsrK = this.DateUsrK; tu1.UsrK = this.UsrK; tu1.ThreadK = t.K; tu1.ChangeStatus(ThreadUsr.StatusEnum.NewInvite); tu1.PrivateChatType = ThreadUsr.PrivateChatTypes.Popup; tu1.StatusChangeObjectK = this.UsrK; tu1.StatusChangeObjectType = Model.Entities.ObjectType.Usr; tu1.Update(); Comment c = new Comment(); c.DateTime = DateTime.Now; if (HttpContext.Current != null) c.Ip = Utilities.TruncateIp(HttpContext.Current.Request.ServerVariables["REMOTE_HOST"]); c.Enabled = true; string rel = ""; if (this.Usr.Relationship1 && this.DateUsr.Relationship1) rel += " <b>just friends</b>"; if (this.Usr.Relationship2 && this.DateUsr.Relationship2) rel += (rel.Length > 0 ? " or " : "") + " <b>a bit of a fling</b>"; if (this.Usr.Relationship3 && this.DateUsr.Relationship3) rel += (rel.Length > 0 ? " or " : "") + " <b>love</b>"; c.Text = "<b>You've both been matched by DSI Date.</b>\n\nYou've selected Yes to each others profiles on the DSI Date page. You're both looking for: " + rel + ".\n\nGet to know each other better in this private conversation."; c.ThreadK = t.K; c.UsrK = 3526; c.DuplicateGuid = Guid.NewGuid(); c.Update(); c = new Comment(c.K); CommentAlert.Enable(this.Usr, t.K, Model.Entities.ObjectType.Thread); CommentAlert.Enable(this.DateUsr, t.K, Model.Entities.ObjectType.Thread); t.LastPost = c.DateTime; t.LastPostUsrK = c.UsrK; t.Update(); t.UpdateTotalComments(null); //t.UpdateTotalParticipants(); UpdateTotalParticipantsJob job = new UpdateTotalParticipantsJob(); job.ExecuteSynchronously(); #endregion this.MatchThreadK = t.K; this.Update(); UsrDate udRev = new UsrDate(this.DateUsrK, this.UsrK); udRev.MatchThreadK = t.K; udRev.Update(); //Email Mailer sm = new Mailer(); sm.RedirectUrl = t.Url(); sm.Subject = "DSI Date has matched you to " + this.DateUsr.NickName; sm.Body = "<p>DSI Date has matched you to " + this.DateUsr.NickNameSafe + ". We've invited you both to a private conversation, where you can get to know each other better.</p>"; sm.Body += "<p><a href=\"[LOGIN(" + t.Url() + ")]\">Click here to send " + this.DateUsr.NickNameSafe + " a message</a></p>"; sm.TemplateType = Mailer.TemplateTypes.AnotherSiteUser; sm.UsrRecipient = this.Usr; sm.To = this.Usr.Email; sm.Send(); Mailer sm1 = new Mailer(); sm1.RedirectUrl = t.Url(); sm1.Subject = "DSI Date has matched you to " + this.Usr.NickName; sm1.Body = "<p>DSI Date has matched you to " + this.Usr.NickNameSafe + ". We've invited you both to a private conversation, where you can get to know each other better.</p>"; sm1.Body += "<p><a href=\"[LOGIN(" + t.Url() + ")]\">Click here to send " + this.Usr.NickNameSafe + " a message</a></p>"; sm1.TemplateType = Mailer.TemplateTypes.AnotherSiteUser; sm1.UsrRecipient = this.DateUsr; sm1.To = this.DateUsr.Email; sm1.Send(); }
/// <summary> /// Returns the current (or creates a new) ThreadUsr for the current thread and the logged in usr. /// </summary> public ThreadUsr GetThreadUsr(Usr u) { ThreadUsr threadUsr = null; if (u != null) { try { threadUsr = new ThreadUsr(this.K, u.K); } catch (BobNotFound) { try { threadUsr = new ThreadUsr(); threadUsr.DateTime = DateTime.Now; threadUsr.IsNew = true; threadUsr.ThreadK = this.K; threadUsr.UsrK = u.K; threadUsr.ChangeStatus(ThreadUsr.StatusEnum.None); threadUsr.Update(); } catch { try { threadUsr = new ThreadUsr(this.K, u.K); } catch { } } } if (threadUsr == null) throw new Exception("Still can't get ThreadUsr after silly complex mess!"); } return threadUsr; }