Exemplo n.º 1
0
		public Comment.Maker GetCommentMaker()
		{
			Comment.Maker m = new Comment.Maker();
			m.AlertedUsrs = new List<int>();
			m.NewThread = false;
			m.ParentThread = this;
			return m;
		}
Exemplo n.º 2
0
			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();
				}
			}
Exemplo n.º 3
0
			protected override void Execute()
			{
				Thread t = new Thread(ThreadK);
				Usr u = new Usr(PostingUsrK);
				Comment.Maker commentMaker = new Comment.Maker();
				commentMaker.ChatItemGuid = ChatItemGuid;
				commentMaker.Body = Body;
				commentMaker.ParentThread = t;
				commentMaker.NewThread = false;
				commentMaker.DuplicateGuid = Guid.NewGuid();
				commentMaker.PostingUsr = u;
				commentMaker.CurrentThreadUsr = t.GetThreadUsr(u);
				if (t.GroupK > 0)
					commentMaker.CurrentGroupUsr = t.Group.GetGroupUsr(u);
				commentMaker.RunAsync = false;
				commentMaker.DisableLiveChatMessage = true;
				commentMaker.Post(null);
			}