public static ModuleRatingInfo initModuleRating(int moduleID) { // Construct a new thread post for ratings for the given module. Modules.ModuleInfo module = Modules.getModuleInfo(moduleID); Post newPost = new Post(); newPost.Username = "******"; newPost.Subject = module.Title; newPost.Body = "Ratings for <a href=\"" + HttpContext.Current.Request.ApplicationPath + "/viewModule.aspx?moduleID=" + module.Id + "\">" + module.Title + "</a>."; newPost.IsLocked = true; newPost.ForumID = FORUMS_ID; // Add the post to the forums database. Post returnedPost = Posts.AddPost(newPost); // Construct a ModuleRatingInfo object with the thread ID of the // actual post created. ModuleRatingInfo modRating = new ModuleRatingInfo(); modRating.ModuleID = module.Id; modRating.ThreadID = returnedPost.ThreadID; ModuleRatings.createRating(modRating); return(modRating); }
public posts NewPost(posts post) { try { Posts posts = new Posts(); post.agree_count = 0; post.disagree_count = 0; post.date_added = DateTime.Now; post.is_approved = true; post.is_deleted = true; posts.AddPost(post); return(post); } catch (Exception ex) { return(null); } }
/// <summary> /// /// </summary> /// <param name="currentInfo"></param> /// <param name="post"></param> /// <param name="rating"></param> /// <returns></returns> public static ModuleRatingInfo addRating(ModuleRatingInfo currentInfo, Post post, Rating rating) { // If post is not null, add the post and rating to forums database. // Even if the post is empty, still add it. if (post != null) { post.PostType = Posts.PostType.Rating; post.ParentID = currentInfo.ThreadID; post.IsLocked = true; post = Posts.AddPost(post); rating.PostID = post.PostID; Ratings.AddRating(rating); } // Calculate the new rating and construct a new ModuleRatingInfo // object to be returned. float newRating = 0; if (currentInfo.NumRatings == 0) { newRating = rating.Value; } else { newRating = (currentInfo.Rating * currentInfo.NumRatings + rating.Value) / (currentInfo.NumRatings + 1); } ModuleRatingInfo newInfo = new ModuleRatingInfo(); newInfo.ModuleID = currentInfo.ModuleID; newInfo.ThreadID = currentInfo.ThreadID; newInfo.Rating = newRating; newInfo.NumRatings = currentInfo.NumRatings + 1; // Update the module rating in the module database. ModuleRatings.updateRating(newInfo); return(newInfo); }
/*********************************************************************** * // PostButton_Click * // * /// <summary> * /// This event handler fires when the preview button is clicked. It needs * /// to show/hide the appropriate panels. * /// </summary> * /// <param name="sender"></param> * /// <param name="e"></param> ************************************************************************/ private void PostButton_Click(Object sender, EventArgs e) { Control form; // Only proceed if the post is valid if (!Page.IsValid) { return; } // Get the user control that the click originated from form = ((Control)sender).Parent; // When we add a new post, we want to get back the NewPostID, so that we // can automagically redirect the user to the page showing the post. // If iNewPostID comes back as 0, though, that means that the post needs // to be approved first, so the user is taken to a page explaining this. Post newPost = null; Post postToAdd = new Post(); postToAdd.Username = Context.User.Identity.Name; postToAdd.ForumID = postToAdd.ParentID = 0; postToAdd.Subject = ((TextBox)form.FindControl("PostSubject")).Text; postToAdd.Body = ((TextBox)form.FindControl("PostBody")).Text; postToAdd.IsLocked = allowNoReplies.Checked; // Are we in edit mode? /* * if (Mode == CreateEditPostMode.EditPost) { * string editNotes = CreateEditNotes(form); * postToAdd.Body = editNotes + postToAdd.Body; * } */ // Are we pinning the post? if ((pinnedPost != null) && (Convert.ToInt32(pinnedPost.SelectedItem.Value) > 0)) { switch (Convert.ToInt32(pinnedPost.SelectedItem.Value)) { case 1: postToAdd.PostDate = DateTime.Now.Date.AddDays(1); break; case 3: postToAdd.PostDate = DateTime.Now.Date.AddDays(3); break; case 7: postToAdd.PostDate = DateTime.Now.Date.AddDays(7); break; case 14: postToAdd.PostDate = DateTime.Now.Date.AddDays(14); break; case 30: postToAdd.PostDate = DateTime.Now.Date.AddMonths(1); break; case 90: postToAdd.PostDate = DateTime.Now.Date.AddMonths(3); break; case 180: postToAdd.PostDate = DateTime.Now.Date.AddMonths(6); break; case 360: postToAdd.PostDate = DateTime.Now.Date.AddYears(1); break; case 999: postToAdd.PostDate = DateTime.Now.Date.AddYears(25); break; } } // Are we adding a new post, editing an existing one, or replying to an existing one? switch (Mode) { case CreateEditPostMode.NewPost: // adding a new post postToAdd.ForumID = ForumID; // specify the forum ID that the new post belongs try { newPost = Posts.AddPost(postToAdd); } catch (PostDuplicateException) { Context.Response.Redirect(Globals.UrlMessage + Convert.ToInt32(Messages.DuplicatePost) + "&ForumId=" + ForumID); Context.Response.End(); } break; case CreateEditPostMode.ReplyToPost: // replying to an existing post try { // if (postView == ViewOptions.Threaded) { postToAdd.ParentID = PostID; // specify the post we are replying to // } else { // postRepliedTo = Posts.GetPost(PostID, user.Username); // postToAdd.ParentID = postRepliedTo.ThreadID; // } newPost = Posts.AddPost(postToAdd); } catch (Components.PostNotFoundException) { // uh-oh, something is off... are we replying to a message that has been deleted? Context.Response.Redirect(Globals.UrlMessage + Convert.ToInt32(Messages.ProblemPosting)); Context.Response.End(); } catch (PostDuplicateException) { Context.Response.Redirect(Globals.UrlMessage + Convert.ToInt32(Messages.DuplicatePost) + "&PostId=" + PostID); Context.Response.End(); } break; case CreateEditPostMode.EditPost: postToAdd.PostID = PostID; // specify the ID of the post we are updating string editedBy = Users.GetLoggedOnUser().Username; // update the post Posts.UpdatePost(postToAdd, editedBy); // send the user back to from where they came Context.Response.Redirect(RedirectURL); Context.Response.End(); // exit from the event handler return; } // now that we've added the post, redirect the user to the post display (if the post // has been approved) if (newPost.Approved) { if (Mode == CreateEditPostMode.NewPost) { Context.Response.Redirect(Globals.UrlShowPost + newPost.ThreadID); } else { Context.Response.Redirect(Globals.UrlShowPost + newPost.ThreadID + "#" + newPost.PostID); } Context.Response.End(); } else { // if the post HASN'T been approved, send the user to an explanation page, passing along the Post or ForumID String strRedirect = Globals.UrlMessage + Convert.ToInt32(Messages.PostPendingModeration); if (ForumID > 0) { Context.Response.Redirect(strRedirect + "&ForumID=" + ForumID.ToString()); } else { Context.Response.Redirect(strRedirect + "&PostID=" + PostID.ToString()); } } }