/// <summary>Builds the custom token dictionary for a discussion post.</summary> /// <param name="post">The discussion post.</param> /// <param name="renderAttachemnts">if set to <c>true</c> [render attachemnts].</param> /// <returns>The custom token dictionary for a discussion post.</returns> private Dictionary <string, string> BuildTokenDictionary(DiscussionPost post, bool renderAttachemnts) { return(new Dictionary <string, string> { { "Discussion:Body", post.Body }, { "Discussion:BodyWithoutMarkup", post.BodyWithoutMarkup.Substring(0, this.MaxContentLength > post.BodyWithoutMarkup.Length ? post.BodyWithoutMarkup.Length : this.MaxContentLength) }, { "Discussion:DiscussionName", post.DiscussionName }, { "Discussion:EmailAddress", post.EmailAddress }, { "Discussion:LinkToDiscussion", post.LinkToDiscussion }, { "Discussion:LinkToMessage", post.LinkToMessage }, { "Discussion:LinkToMessageInContext", post.LinkToMessageInContext }, { "Discussion:MessageStatus", post.MessageStatus }, { "Discussion:ModerationType", post.ModerationType }, { "Discussion:Subject", post.Subject.Substring(0, this.MaxContentLength > post.Subject.Length ? post.Subject.Length : this.MaxSubjectLength) }, { "Discussion:ContactKey", post.ContactKey.ToString() }, { "Discussion:DiscussionPostKey", post.DiscussionPostKey.ToString() }, { "Discussion:DiscussionKey", post.DiscussionKey.ToString() }, { "Discussion:DatePosted", post.DatePosted.ToString(this.DateFormat, CultureInfo.CurrentCulture) }, { "Discussion:Pinned", post.Pinned.ToString() }, { "Discussion:RecommendationCount", post.RecommendationCount.ToString() }, { "Discussion:Attachments", this.GetPostAttachmentMarkup(post.Attachments, renderAttachemnts) }, { "Author:LinkToProfile", post.Author.LinkToProfile }, { "Author:PictureUrl", post.Author.PictureUrl }, { "Author:ContactKey", post.Author.ContactKey.ToString() }, { "Author:FirstName", post.Author.FirstName }, { "Author:LastName", post.Author.LastName }, { "Author:DisplayName", post.Author.DisplayName }, { "Author:EmailAddress", post.Author.EmailAddress }, { "Author:CompanyName", post.Author.CompanyName }, { "Author:CompanyTitle", post.Author.CompanyTitle }, { "Author:Designation", post.Author.Designation }, { "Author:MiddleName", post.Author.MiddleName }, }); }
static CreateDiscussion() { API ClarizenAPI = new API(); if (!ClarizenAPI.Login(ConfigurationManager.AppSettings["username"], ConfigurationManager.AppSettings["password"])) { return; } string parentTaskId = "/Task/4batkam0jt4xn0l3cdx4y8ueg4"; DiscussionPost discussionPost = new DiscussionPost("/DiscussionPost", "This discussion is created by API", parentTaskId, "Integration Tool"); Clarizen.API.V2_0.Data.createDiscussion op = ClarizenAPI.CreateDiscussion(discussionPost); if (op.IsCalledSuccessfully) { Console.WriteLine("Discussion created successfully"); } else { Console.WriteLine(op.Error); } if (ClarizenAPI.Logout()) { Console.WriteLine("{0} API calls made in this session", ClarizenAPI.TotalAPICallsMadeInCurrentSession); } }
public int MoveToDiscussion(ManagedSecurityContext sec, int targetid) { GetACL().Check(sec, DataOperation.Delete); ManagedDiscussion target_discussion = new ManagedDiscussion(Session, targetid); target_discussion.GetACL().Check(sec, DataOperation.Create); // create the target thread DiscussionThread target_thread = new DiscussionThread(); target_thread.Discussion = target_discussion.Instance; target_thread.Modified = mInstance.Modified; target_thread.Created = mInstance.Created; Session.Save(target_thread); if (target_discussion.Instance.Modified < mInstance.Modified) { target_discussion.Instance.Modified = mInstance.Modified; Session.Save(target_discussion.Instance); } // copy the post to a discusison post DiscussionPost target_post = new DiscussionPost(); target_post.AccountId = mInstance.AccountId; target_post.Body = mInstance.Body; target_post.Created = mInstance.Created; target_post.Modified = mInstance.Modified; target_post.Sticky = false; target_post.Subject = mInstance.Title; target_post.DiscussionThread = target_thread; Session.Save(target_post); // set the new post as parent of all replies int comments_discussion_id = ManagedDiscussion.GetOrCreateDiscussionId( Session, typeof(AccountBlogPost).Name, mInstance.Id, sec); Discussion comments_discussion = Session.Load <Discussion>(comments_discussion_id); foreach (DiscussionThread thread in Collection <DiscussionThread> .GetSafeCollection(comments_discussion.DiscussionThreads)) { foreach (DiscussionPost post in thread.DiscussionPosts) { post.DiscussionThread = target_thread; if (post.DiscussionPostParent == null) { post.DiscussionPostParent = target_post; } } Session.Delete(thread); } // delete the current post that became a discussion post Session.Delete(mInstance); return(target_post.Id); }
public ActionResult NewReply(DiscussionPost reply) { if (reply.Content != null && reply.ParentPostID > 0 && reply.DiscussionTeamID > 0 && reply.AssignmentID > 0) { Assignment assignment = db.Assignments.Find(reply.AssignmentID); reply.CourseUserID = ActiveCourseUser.ID; db.DiscussionPosts.Add(reply); db.SaveChanges(); SendModeratorEmail(assignment, reply); SendUserEmail(assignment, reply); } return(Redirect(Request.UrlReferrer.ToString())); }
public ActionResult NewPost(DiscussionPost newPost) { if (newPost != null && newPost.Content != null && newPost.AssignmentID > 0 && newPost.DiscussionTeamID > 0) { Assignment assignment = db.Assignments.Find(newPost.AssignmentID); newPost.CourseUserID = ActiveCourseUser.ID; db.DiscussionPosts.Add(newPost); db.SaveChanges(); SendModeratorEmail(assignment, newPost); SendUserEmail(assignment, newPost); } return(Redirect(Request.UrlReferrer.ToString())); }
private void SendModeratorEmail(Assignment assignment, DiscussionPost newPost) { if (assignment.DiscussionSettings != null) { if (assignment.DiscussionSettings.WillEmailInstructorsOnModeratorPost == true) { if (newPost.CourseUser.AbstractRoleID == (int)CourseRole.CourseRoles.TA || newPost.CourseUser.AbstractRoleID == (int)CourseRole.CourseRoles.Moderator) { //mail all instructors List <MailAddress> to = new List <MailAddress>(); List <string> emailAddresses = db.CourseUsers .Where(cu => cu.AbstractRole.CanGrade == true) .Where(cu => cu.AbstractCourseID == assignment.CourseID) .Select(cu => cu.UserProfile.UserName) .ToList(); foreach (string address in emailAddresses) { //AC: sometimes this fails. Not sure why try { to.Add(new MailAddress(address)); } catch (Exception) { } } string subject = "[OSBLE][Moderator] - New Post in " + assignment.Course.Name; string linkUrl = string.Format("http://plus.osble.org{0}", Url.Action("TeacherIndex", "DiscussionAssignment", new { assignmentID = assignment.ID, discussionTeamID = newPost.DiscussionTeamID })); string body = @" Greetings, {0} has posted the following message on the discussion assignment ""{1}."": {2} You may view the discussion on OSBLE by visiting the following link: <a href=""{3}"">{4}</a>. "; body = string.Format(body, ActiveCourseUser.UserProfile.DisplayName((int)CourseRole.CourseRoles.Instructor, true), assignment.AssignmentName, newPost.Content, linkUrl, linkUrl ); Email.Send(subject, body, to); } } } }
public IHttpActionResult GetParentPost(int id) { using (DbEntities _db = new DbEntities()) { var s = _db.DiscussionPosts.Find(id); if (s != null) { var result = new DiscussionPost(); result.Id = s.Id; result.DiscussionId = s.DiscussionId; result.Topic = s.Topic; return(Ok(result)); } } return(NotFound()); }
public IHttpActionResult AddDiscussionReply([FromBody] DiscussionPost model) { using (DbEntities _db = new DbEntities()) { DiscussionPost _post = new DiscussionPost(); _post.DiscussionId = model.DiscussionId; _post.ParentId = model.ParentId; _post.Topic = model.Topic; _post.Message = model.Message; _post.IsDeleted = model.IsDeleted; _post.UserId = model.UserId; _post.CreatedBy = model.CreatedBy; _post.CreatedDate = model.CreatedDate; _post.UpdatedBy = model.UpdatedBy; db.DiscussionPosts.Add(_post); db.SaveChanges(); return(Ok(_post)); } }
public async Task <ActionResult> CreateNewComment(DiscussionView NewPost) { if (NewPost != null) { if (NewPost.NewDiscussionReply != null) { var DiscussionResponse = await WepApiMethod.SendApiAsync <DiscussionPost>(HttpVerbs.Get, $"eLearning/CourseDiscussion/GetParentPost?id={NewPost.NewDiscussionReply.ParentId}"); if (DiscussionResponse.isSuccess) { var parentPost = DiscussionResponse.Data; if (NewPost.NewDiscussionReply != null) { DateTime _now = DateTime.Now; DiscussionPost _post = new DiscussionPost(); _post.DiscussionId = parentPost.DiscussionId; _post.ParentId = parentPost.Id; _post.Topic = parentPost.Topic; _post.Message = NewPost.NewDiscussionReply.Message; _post.IsDeleted = false; _post.UserId = CurrentUser.UserId.Value; _post.CreatedBy = CurrentUser.UserId.Value; _post.CreatedDate = _now; _post.UpdatedBy = CurrentUser.UserId.Value; db.DiscussionPosts.Add(_post); db.SaveChanges(); return(RedirectToAction("View", new { id = parentPost.DiscussionId })); } } else { } } } return(RedirectToAction("List")); }
public async Task <ActionResult> CreateNewReply(DiscussionView NewPost) { if (NewPost != null) { if (NewPost.NewDiscussionReply != null) { DateTime _now = DateTime.Now; int _attachmentId = 0; //int attachmentId = SaveAttachment(_now, Request.Files).Result; foreach (string file in Request.Files)// set 1 only { for (int i = 0; i < Request.Files.Count; i++) { var filex = Request.Files[i]; if (!String.IsNullOrEmpty(filex.FileName)) { var fileName = Path.GetFileName(filex.FileName); var fileId = _now.Ticks.ToString() + "_" + fileName; var fullPath = Path.Combine(StorageRoot, fileId); try { System.IO.Directory.CreateDirectory(StorageRoot); filex.SaveAs(fullPath); var attachment = new CreateCourseDiscussionAttachmentModel() { Id = 0, FileName = fileName, FileSize = filex.ContentLength, FileType = filex.ContentType, FilePath = @"~\App_Data\DiscussionAttachment\" + fileId, FileTag = "", FileNameOnStorage = fileId, CreatedBy = CurrentUser.UserId.Value, CreatedDate = _now, }; var attachmentresponse = await WepApiMethod.SendApiAsync <int>(HttpVerbs.Post, $"eLearning/CourseDiscussion/CreateAttachment", attachment); if (attachmentresponse.isSuccess) { _attachmentId = attachmentresponse.Data; } } catch { TempData["ErrorMessage"] = "Error save attachment"; //return RedirectToAction("List"); } } } } // add attachment // add reply (attach attachment id if any) DiscussionPost _post = new DiscussionPost(); _post.DiscussionId = NewPost.NewDiscussionReply.DiscussionId; _post.ParentId = null; _post.Topic = ""; _post.Message = NewPost.NewDiscussionReply.Message; _post.IsDeleted = false; _post.UserId = CurrentUser.UserId.Value; _post.CreatedBy = CurrentUser.UserId.Value; _post.CreatedDate = _now; _post.UpdatedBy = CurrentUser.UserId.Value; //db.DiscussionPosts.Add(_post); //db.SaveChanges(); var addNewReply = await WepApiMethod.SendApiAsync <DiscussionPost>(HttpVerbs.Post, $"eLearning/CourseDiscussion/AddDiscussionReply", _post); if (addNewReply.isSuccess) { var addedReply = addNewReply.Data; if (_attachmentId > 0) { var linkAttachment = await WepApiMethod.SendApiAsync <bool>(HttpVerbs.Post, $"eLearning/CourseDiscussion/AddAttachmentToDisccusion?pid={addedReply.Id}&aid={_attachmentId}"); if (linkAttachment.isSuccess) { } else { } //DiscussionAttachment _attachment = new DiscussionAttachment() //{ // AttachmentId = _attachmentId, // PostId = _post.Id, //}; //db.DiscussionAttachment.Add(_attachment); //db.SaveChanges(); } } else { //error } } } return(RedirectToAction("View", new { id = NewPost.NewDiscussionReply.DiscussionId })); }
private void SendUserEmail(Assignment assignment, DiscussionPost newPost) { //mail all users in the course with mail new discussion post setting set as true List <MailAddress> to = new List <MailAddress>(); List <string> emailAddresses = new List <string>(); Dictionary <int, string> teamMembers = new Dictionary <int, string>(); List <Team> teams = db.DiscussionTeams .Where(dt => dt.AssignmentID == assignment.ID) .Where(dt => dt.ID == newPost.DiscussionTeamID) .Select(dt => dt.Team) .ToList(); if (teams != null) { foreach (TeamMember member in teams[0].TeamMembers) { teamMembers.Add(member.CourseUserID, member.CourseUser.UserProfile.UserName.ToString()); } } //TODO: check this to see if it's not working as it should... user claims they got an email before they should have. if (assignment.DiscussionSettings.RequiresPostBeforeView == true) { Dictionary <int, string> PossibleUsers = db.CourseUsers .Where(cu => cu.AbstractCourseID == assignment.CourseID) .Where(cu => cu.UserProfileID != ActiveCourseUser.UserProfileID) .Where(cu => cu.AbstractRoleID == 3) .Where(cu => cu.UserProfile.EmailNewDiscussionPosts == true) .Select(cu => new { cu.ID, cu.UserProfile.UserName }) .ToDictionary(cu => cu.ID, cu => cu.UserName); Dictionary <int, String> RealTeammembers = new Dictionary <int, string>(); if (teams != null) { foreach (KeyValuePair <int, string> possible_user in PossibleUsers) { if (!(teamMembers.ContainsKey(possible_user.Key))) { } else { RealTeammembers.Add(possible_user.Key, possible_user.Value); } } PossibleUsers = RealTeammembers; } foreach (DiscussionPost post in db.DiscussionPosts) { //TODO: check here... why is this not working? if (PossibleUsers.ContainsKey(post.CourseUserID) && !(emailAddresses.Contains(PossibleUsers[post.CourseUserID].ToString()))) { emailAddresses.Add(PossibleUsers[post.CourseUserID].ToString()); } } } else { if (teams != null) { Dictionary <int, string> PossibleUsers = db.CourseUsers .Where(cu => cu.AbstractCourseID == assignment.CourseID) .Where(cu => cu.UserProfileID != ActiveCourseUser.UserProfileID) .Where(cu => cu.AbstractRoleID == 3) .Where(cu => cu.UserProfile.EmailNewDiscussionPosts == true) .Select(cu => new { cu.ID, cu.UserProfile.UserName }) .ToDictionary(cu => cu.ID, cu => cu.UserName); Dictionary <int, String> RealTeammembers = new Dictionary <int, string>(); foreach (KeyValuePair <int, string> possible_user in PossibleUsers) { if (!(teamMembers.ContainsKey(possible_user.Key))) { } else { RealTeammembers.Add(possible_user.Key, possible_user.Value); } } foreach (KeyValuePair <int, string> possible_user in RealTeammembers) { emailAddresses.Add(possible_user.Value); } } else { emailAddresses = db.CourseUsers .Where(cu => cu.AbstractCourseID == assignment.CourseID) .Where(cu => cu.UserProfileID != ActiveCourseUser.UserProfileID) .Where(cu => cu.AbstractRoleID == 3) .Where(cu => cu.UserProfile.EmailNewDiscussionPosts == true) .Select(cu => cu.UserProfile.UserName) .ToList(); } } foreach (string address in emailAddresses) { //AC: sometimes this fails. Not sure why try { to.Add(new MailAddress(address)); } catch (Exception) { } } bool anonSettings = false; if (assignment.DiscussionSettings.AnonymitySettings > 0) { anonSettings = true; } string subject = "[OSBLE][Discussion] - New Post in " + assignment.Course.Name; string linkUrl = string.Format("http://plus.osble.org{0}", Url.Action("TeacherIndex", "DiscussionAssignment", new { assignmentID = assignment.ID, discussionTeamID = newPost.DiscussionTeamID })); string body = @" Greetings, {0} has posted the following message on the discussion assignment ""{1}."": {2} You may view the discussion on OSBLE by visiting the following link: <a href=""{3}"">{4}</a>. "; body = string.Format(body, ActiveCourseUser.UserProfile.DisplayName(ActiveCourseUser.AbstractRoleID, true, anonSettings), assignment.AssignmentName, newPost.Content, linkUrl, linkUrl ); Email.Send(subject, body, to); }
public IHttpActionResult Post([FromBody] CreateCourseDiscussionModel model) { // create new entry for discussion // create new entry for post // create new link from post to attachment if any try { using (DbEntities _db = new DbEntities()) { DateTime _now = DateTime.Now; Discussion _discussion = new Discussion() { Name = model.Name, CreatedBy = model.UserId, UpdatedBy = model.UserId, UserId = model.UserId, CreatedDate = _now, DiscussionVisibility = model.DiscussionVisibility, Pinned = false, IsDeleted = false, FirstPost = 0, }; if (model.DiscussionVisibility == DiscussionVisibility.Everybody) { } else if (model.DiscussionVisibility == DiscussionVisibility.GroupOnly) { _discussion.GroupId = model.GroupId; } _db.Discussions.Add(_discussion); _db.SaveChanges(); DiscussionPost _post = new DiscussionPost() { DiscussionId = _discussion.Id, ParentId = null, Topic = model.Name, Message = model.Post.Message, IsDeleted = false, UserId = model.Post.UserId.Value, CreatedBy = model.Post.UserId.Value, CreatedDate = _now, UpdatedBy = model.Post.UserId.Value, UpdatedDate = _now }; _db.DiscussionPosts.Add(_post); _db.SaveChanges(); if (model.Post.GotAttachment.HasValue) { if (model.Post.GotAttachment.Value && (model.AttachmentId != null)) { DiscussionAttachment _attachment = new DiscussionAttachment() { AttachmentId = model.AttachmentId.Value, PostId = _post.Id, }; _db.DiscussionAttachment.Add(_attachment); _db.SaveChanges(); } } //var updateFirstPost var _toUpdateFirstPost = _db.Discussions.Find(_discussion.Id); if (_toUpdateFirstPost != null) { _toUpdateFirstPost.FirstPost = _post.Id; db.Discussions.Attach(_toUpdateFirstPost); db.Entry(_toUpdateFirstPost).Property(m => m.FirstPost).IsModified = true; db.Configuration.ValidateOnSaveEnabled = false; db.SaveChanges(); } return(Ok(_discussion.Id)); } } catch (Exception ex) { Debug.WriteLine(ex.Message); return(Ok()); //return ex.InnerException.Message.ToString(); } }