Esempio n. 1
0
        /// <summary>
        /// 编辑一个主题的信息
        /// </summary>
        /// <param name="entity">待更新的主题实体</param>
        /// <returns>是否更新成功</returns>
        public void EditThread(UpdateThreadModel entity)
        {
            //创建主题仓储
            IForumThreadRepository forumThreadRep = FBS.Factory.Factory <IForumThreadRepository> .GetConcrete();

            try
            {
            }
            catch
            {
                throw new UpdateForumThreadException("更新主题至仓储时异常");
            }
        }
Esempio n. 2
0
        public async Task <ActionResult> SubmitUpdateThread(UpdateThreadModel model)
        {
            if (ModelState.IsValid)
            {
                var sanitizer = new HtmlSanitizer();
                using (var context = new ApplicationDbContext())
                {
                    var thread = await context.ForumThreads.FirstOrDefaultAsync(x => x.Id == model.ThreadId && !x.IsDeleted);

                    if (thread == null)
                    {
                        return(ViewMessage(new ViewMessageModel(ViewMessageType.Warning, Resources.Forum.threadNotFoundErrorTitle, Resources.Forum.threadNotFoundErrorMessage)));
                    }

                    if (!(User.IsInRole("Admin") || User.IsInRole("Moderator")))
                    {
                        if (!thread.UserId.Equals(User.Identity.GetUserId(), StringComparison.OrdinalIgnoreCase))
                        {
                            return(ViewMessage(new ViewMessageModel(ViewMessageType.Warning, Resources.Forum.threadUpdatePermitionErrorTitle, Resources.Forum.threadUpdatePermitionErrorMessage)));
                        }
                    }

                    var firstPost = thread.Posts.FirstOrDefault(x => x.IsFirstPost && !x.IsDeleted);
                    if (firstPost == null)
                    {
                        return(ViewMessage(new ViewMessageModel(ViewMessageType.Warning, Resources.Forum.threadNotFoundErrorTitle, Resources.Forum.threadNotFoundErrorMessage)));
                    }

                    firstPost.LastUpdate = DateTime.UtcNow;
                    thread.LastUpdate    = DateTime.UtcNow;
                    firstPost.Message    = sanitizer.Sanitize(model.Message);
                    thread.Title         = model.Title;
                    await context.SaveChangesAsync().ConfigureAwait(false);

                    return(RedirectToAction("Thread", new { id = model.ThreadId }));
                }
            }
            return(View("UpdateThread", model));
        }