public void AuthorizeCreatePost(CreatePostInfo info) { // Check user has minimum permissions required _functionAuthorizer.Authorize(new UserFunction { Function = ForumFunctions.ForumUser, UserId = info.UserId, TenantId = info.TenantId }); }
public long CreatePost(CreatePostInfo info, IUnitOfWork unitOfWork = null) { // Check user permissions _forumAuthorizer.AuthorizeCreatePost(info); // Validate supplied post details _forumValidator.ValidateCreatePost(info); // Remove extraneous white space info.Message = info.Message.Trim(); // Create forum post long postId = _forumRepository.CreatePost(info, DateTime.UtcNow, unitOfWork); // Get thread details to determine whether or not notification should be sent to thread owner ForumThread thread = _forumRepository.GetThread(info.TenantId, info.ElementId, info.ThreadId, unitOfWork); if (thread.Notify && thread.UserId != info.UserId) { // Ger details of user who started thread User user = _userRepository.ReadUser(info.TenantId, thread.UserId, unitOfWork); User postUser = _userRepository.ReadUser(info.TenantId, info.UserId, unitOfWork); // Get email that will be sent to thread owner int threadPage = GetThreadPage(info.TenantId, info.ElementId, info.ThreadId, postId, unitOfWork); int? page = threadPage == 0 ? (int?)null : threadPage + 1; Email email = _forumConfigurationService.GetCreatePostEmail(user.Email, user.Alias, postId, page, thread.Subject, postUser.Alias); // Send email _emailService.SendEmail(email); } // Return newly allocated post identifier return(postId); }
public long CreatePost(CreatePostInfo info, DateTime created, IUnitOfWork unitOfWork = null) { IUnitOfWork localUnitOfWork = unitOfWork == null?_unitOfWorkFactory.CreateUnitOfWork() : null; try { IDatabaseManager dbm = _databaseManagerFactory.GetDatabaseManager(unitOfWork ?? localUnitOfWork); string sql = _sqlManager.GetSql("Sql.CreateForumPost.sql"); dbm.SetSQL(sql); dbm.AddParameter("@TenantId", FieldType.BigInt, info.TenantId); dbm.AddParameter("@ElementId", FieldType.BigInt, info.ElementId); dbm.AddParameter("@ThreadId", FieldType.BigInt, info.ThreadId); dbm.AddParameter("@ParentPostId", FieldType.BigInt, info.ParentPostId == null ? (object)DBNull.Value : (object)info.ParentPostId); dbm.AddParameter("@UserId", FieldType.BigInt, info.UserId); dbm.AddParameter("@Message", FieldType.NVarChar, -1, info.Message); dbm.AddParameter("@Created", FieldType.DateTime, created); dbm.AddOutputParameter("@PostId", FieldType.BigInt); Dictionary <string, object> outputValues = new Dictionary <string, object>(); dbm.ExecuteNonQuery(outputValues); if (localUnitOfWork != null) { localUnitOfWork.Commit(); } return((long)outputValues["@PostId"]); } catch { if (localUnitOfWork != null) { localUnitOfWork.Rollback(); } throw; } finally { if (localUnitOfWork != null) { localUnitOfWork.Dispose(); } } }
private FormResult PostReplyQuotePostForm(Form form) { // Get logged on user details long tenantId = _authenticationService.TenantId; long userId = _authenticationService.GetCurrentUser().User.UserId; // Get page, element and thread identifiers string[] parts = form.Context.Split('|'); long pageId = Convert.ToInt64(parts[1]); long elementId = Convert.ToInt64(parts[2]); long threadId = Convert.ToInt64(parts[3]); long postId = Convert.ToInt64(parts[4]); // Get existing thread details ForumThread forumThread = _forumService.GetThread(tenantId, elementId, threadId); // Get information required to create post CreatePostInfo info = new CreatePostInfo { ElementId = elementId, Message = ((MultiLineTextField)form.Fields["message"]).Value, ParentPostId = postId, TenantId = tenantId, ThreadId = threadId, UserId = userId, }; // Create new post long newPostId = _forumService.CreatePost(info); // Get thread page that new post is on int page = _forumService.GetThreadPage(tenantId, info.ElementId, info.ThreadId, newPostId); // Return form result with no errors string status = _forumUrlService.GetThreadUrl(pageId, threadId, forumThread.Subject, page); return(_formHelperService.GetFormResult(status)); }
public void ValidateCreatePost(CreatePostInfo info) { _modelValidator.Validate(info); }