Exemple #1
0
        public async Task <OpResult> UpsertForumThreadPost(ForumThreadPostModel forumThreadPost, Guid forumUserGuid, bool isForumAdmin, bool importFlag = false)
        {
            var retvalue = new OpResult();
            ForumThreadPostModel existingForumThreadPost = null;

            if (forumThreadPost == null)
            {
                retvalue.LogError(POST_ERROR_DATA_MUST_BE_PROVIDED);
                return(retvalue);
            }
            if (!importFlag)
            {
                if (forumThreadPost.Guid != Guid.Empty)
                {
                    existingForumThreadPost = await _forumDal.GetForumThreadPostById(forumThreadPost.Guid);

                    if (existingForumThreadPost == null)
                    {
                        retvalue.LogError(POST_ERROR_INVALID_RECORD);
                    }
                    else
                    {
                        forumThreadPost.CreatedUTC    = existingForumThreadPost.CreatedUTC;
                        forumThreadPost.ModifiedUTC   = existingForumThreadPost.ModifiedUTC;
                        forumThreadPost.ForumUserGuid = existingForumThreadPost.ForumUserGuid;
                        if (!isForumAdmin)
                        {
                            forumThreadPost.ForumThreadGuid = existingForumThreadPost.ForumThreadGuid;
                            forumThreadPost.LockFlag        = existingForumThreadPost.LockFlag;
                            forumThreadPost.VisibleFlag     = existingForumThreadPost.VisibleFlag;
                            if (forumThreadPost.ForumUserGuid != forumUserGuid || !forumThreadPost.VisibleFlag || forumThreadPost.LockFlag)
                            {
                                retvalue.LogError(POST_ERROR_NOT_AUTHORIZED);
                            }
                            if (forumThreadPost.CreatedUTC.HasValue &&
                                (DateTime.UtcNow - forumThreadPost.CreatedUTC.Value).TotalMinutes > _settingsProvider.Current.TimeLimitForumPostEdit)
                            {
                                retvalue.LogError(POST_ERROR_TOO_LATE_TO_UPDATE);
                            }
                        }
                    }
                }
                else
                {
                    forumThreadPost.ForumUserGuid = forumUserGuid;
                }
            }
            if (string.IsNullOrWhiteSpace(forumThreadPost.Data))
            {
                retvalue.LogError(POST_ERROR_CONTENT_IS_REQUIRED);
            }
            if (retvalue.Successful)
            {
                if (importFlag || forumThreadPost.Guid == Guid.Empty)
                {
                    await _forumDal.InsertForumThreadPost(forumThreadPost, importFlag);
                }
                else
                {
                    await _forumDal.UpdateForumThreadPost(forumThreadPost);
                }
            }
            return(retvalue);
        }