예제 #1
0
        public ActionResult _ChildComment(long?parentId)
        {
            if (!parentId.HasValue)
            {
                return(HttpNotFound());
            }

            CommentService commentService = new CommentService();
            Comment        comment        = commentService.Get(parentId.Value);

            if (comment == null)
            {
                return(HttpNotFound());
            }

            MicroblogEntity entity = microblogService.Get(comment.CommentedObjectId);

            if (entity == null)
            {
                return(HttpNotFound());
            }

            MicroblogCommentEditModel editModel = comment.AsMicroblogCommentEditModel();

            editModel.OriginalAuthor = entity.Author;

            return(View(editModel));
        }
예제 #2
0
        public ActionResult Detail(string spaceKey, long microblogId)
        {
            MicroblogEntity entity = microblogService.Get(microblogId);

            if (entity == null)
            {
                return(HttpNotFound());
            }

            //验证是否通过审核
            long currentSpaceUserId = UserIdToUserNameDictionary.GetUserId(spaceKey);

            if (!authorizer.IsAdministrator(MicroblogConfig.Instance().ApplicationId) && entity.UserId != currentSpaceUserId &&
                (int)entity.AuditStatus < (int)(new AuditService().GetPubliclyAuditStatus(MicroblogConfig.Instance().ApplicationId)))
            {
                return(Redirect(SiteUrls.Instance().SystemMessage(TempData, new SystemMessageViewModel
                {
                    Title = "尚未通过审核",
                    Body = "由于当前微博尚未通过审核,您无法浏览当前内容。",
                    StatusMessageType = StatusMessageType.Hint
                })));
            }

            IUser user = userService.GetUser(spaceKey);

            if (user == null)
            {
                return(new EmptyResult());
            }


            pageResourceManager.InsertTitlePart(user.DisplayName + "的微博");

            return(View(entity));
        }
예제 #3
0
        /// <summary>
        /// 删除微博
        /// </summary>
        /// <param name="microblogId">微博Id</param>
        public void Delete(long microblogId)
        {
            MicroblogEntity entity = Get(microblogId);

            if (entity == null)
            {
                return;
            }

            var sender = new CommentService().GetCommentedObjectComments(microblogId);



            EventBus <MicroblogEntity> .Instance().OnBefore(entity, new CommonEventArgs(EventOperationType.Instance().Delete()));

            int affect = microblogRepository.Delete(entity);

            if (affect > 0)
            {
                //删除微博时评论的积分处理
                if (sender != null)
                {
                    EventBus <Comment> .Instance().OnBatchAfter(sender, new CommonEventArgs(EventOperationType.Instance().Delete()));
                }
                //更新用户数据
                OwnerDataService ownerDataService = new OwnerDataService(entity.TenantTypeId);
                ownerDataService.Change(entity.OwnerId, OwnerDataKeys.Instance().ThreadCount(), -1);

                EventBus <MicroblogEntity> .Instance().OnAfter(entity, new CommonEventArgs(EventOperationType.Instance().Delete()));

                EventBus <MicroblogEntity, AuditEventArgs> .Instance().OnAfter(entity, new AuditEventArgs(entity.AuditStatus, null));
            }
        }
예제 #4
0
        /// <summary>
        /// MicroblogEntity转换成<see cref="Lucene.Net.Documents.Document"/>
        /// </summary>
        /// <param name="microblog">微博实体</param>
        /// <returns>Lucene.Net.Documents.Document</returns>
        public static Document Convert(MicroblogEntity microblog)
        {
            Document doc = new Document();

            //索引微博基本信息
            doc.Add(new Field(MicroblogIndexDocument.MicroblogId, microblog.MicroblogId.ToString(), Field.Store.YES, Field.Index.NOT_ANALYZED));
            if (microblog.OriginalMicroblog != null)
            {
                doc.Add(new Field(MicroblogIndexDocument.Body, HtmlUtility.StripHtml(microblog.Body, true, false).ToLower() + HtmlUtility.StripHtml(microblog.OriginalMicroblog.Body, true, false).ToLower(), Field.Store.NO, Field.Index.ANALYZED));
            }
            else
            {
                doc.Add(new Field(MicroblogIndexDocument.Body, HtmlUtility.StripHtml(microblog.Body, true, false).ToLower(), Field.Store.NO, Field.Index.ANALYZED));
            }
            doc.Add(new Field(MicroblogIndexDocument.DateCreated, DateTools.DateToString(microblog.DateCreated, DateTools.Resolution.MILLISECOND), Field.Store.YES, Field.Index.NOT_ANALYZED));
            doc.Add(new Field(MicroblogIndexDocument.HasMusic, microblog.HasMusic ? "1" : "0", Field.Store.YES, Field.Index.NOT_ANALYZED));
            doc.Add(new Field(MicroblogIndexDocument.HasPhoto, microblog.HasPhoto ? "1" : "0", Field.Store.YES, Field.Index.NOT_ANALYZED));
            doc.Add(new Field(MicroblogIndexDocument.HasVideo, microblog.HasVideo ? "1" : "0", Field.Store.YES, Field.Index.NOT_ANALYZED));
            doc.Add(new Field(MicroblogIndexDocument.IsOriginality, microblog.ForwardedMicroblogId == 0 ? "1" : "0", Field.Store.YES, Field.Index.NOT_ANALYZED));
            doc.Add(new Field(MicroblogIndexDocument.TenantTypeId, microblog.TenantTypeId, Field.Store.YES, Field.Index.NOT_ANALYZED));


            TagService tagService = new TagService(TenantTypeIds.Instance().Microblog());

            IEnumerable <ItemInTag> itemInTags = tagService.GetItemInTagsOfItem(microblog.MicroblogId);

            foreach (ItemInTag itemInTag in itemInTags)
            {
                doc.Add(new Field(MicroblogIndexDocument.Topic, itemInTag.TagName.ToLower(), Field.Store.YES, Field.Index.ANALYZED));
            }

            return(doc);
        }
예제 #5
0
        /// <summary>
        /// 微博详细显示页
        /// </summary>
        /// <param name="spaceKey"></param>
        /// <param name="MicroblogId"></param>
        /// <param name="commentId"></param>
        /// <returns></returns>
        public string MicroblogDetail(long microblogId, long?commentId = null)
        {
            MicroblogEntity microblog = DIContainer.Resolve <MicroblogService>().Get(microblogId);

            if (microblog == null || microblog.User == null)
            {
                return(string.Empty);
            }

            return(SiteUrls.Instance().ShowMicroblog(microblog.User.UserName, microblogId, commentId));
        }
        public JsonResult Delete(string spaceKey, long microblogId)
        {
            MicroblogEntity microblog = microblogService.Get(microblogId);

            if (!authorizer.Microblog_Delete(microblog))
            {
                return(Json(new StatusMessageData(StatusMessageType.Error, "删除失败!"), JsonRequestBehavior.AllowGet));
            }

            microblogService.Delete(microblogId);
            return(Json(new StatusMessageData(StatusMessageType.Success, "删除成功!"), JsonRequestBehavior.AllowGet));
        }
예제 #7
0
파일: Microblog.cs 프로젝트: x1987624/SNS
        /// <summary>
        /// 新建实体时使用
        /// </summary>
        //todo:需要检查成员初始化的类型是否正确
        public static MicroblogEntity New()
        {
            MicroblogEntity microblog = new MicroblogEntity()
            {
                Author      = string.Empty,
                Body        = string.Empty,
                PostWay     = PostWay.Web,
                DateCreated = DateTime.UtcNow,
                IP          = WebUtility.GetIP()
            };

            return(microblog);
        }
        public ActionResult ForwardMicroblog(string forwardBody)
        {
            if (!ValidateContentLength(forwardBody))
            {
                return(Json(new { MessageData = new StatusMessageData(StatusMessageType.Error, "内容超出字数限制!") }));
            }

            bool isBanned = ModelState.HasBannedWord();

            forwardBody = Tunynet.Utilities.WebUtility.HtmlEncode(forwardBody);
            if (isBanned)
            {
                return(Json(new { MessageData = new StatusMessageData(StatusMessageType.Error, "内容中包含非法词语!") }));
            }

            bool isCommnet         = Request.Form.GetBool("isCommnet", false);
            bool isCommentOriginal = Request.Form.GetBool("isCommentOriginal", false);

            IUser currentUser = UserContext.CurrentUser;

            MicroblogEntity microblog = MicroblogEntity.New();

            microblog.Body                 = string.IsNullOrEmpty(forwardBody) ? "转发微博" : forwardBody;
            microblog.Author               = currentUser.DisplayName;
            microblog.UserId               = currentUser.UserId;
            microblog.OwnerId              = currentUser.UserId;
            microblog.TenantTypeId         = TenantTypeIds.Instance().User();
            microblog.ForwardedMicroblogId = Request.Form.Get <long>("forwardedMicroblogId", 0);
            microblog.OriginalMicroblogId  = Request.Form.Get <long>("originalMicroblogId", 0);

            if (!authorizer.Microblog_Create(microblog.TenantTypeId, microblog.OwnerId))
            {
                return(Json(new { MessageData = new StatusMessageData(StatusMessageType.Error, "您没有权限进行转发!") }));
            }

            long toUserId         = Request.Form.Get <long>("toUserId", 0);
            long toOriginalUserId = Request.Form.Get <long>("toOriginalUserId", 0);
            //reply:已修改
            long microblogId = 0;
            bool isSuccess   = microblogService.Forward(microblog, isCommnet, isCommentOriginal, toUserId, toOriginalUserId, out microblogId);

            if (isSuccess)
            {
                string url = SiteUrls.Instance()._Microblog(microblogId);
                return(Json(new { Url = url, MessageData = new StatusMessageData(StatusMessageType.Success, "转发成功!") }));
            }
            else
            {
                return(Json(new { MessageData = new StatusMessageData(StatusMessageType.Error, "转发失败!") }));
            }
        }
예제 #9
0
        /// <summary>
        /// 微博列表,单条空间 - 通过动态获取
        /// </summary>
        /// <param name="activityId">动态Id</param>
        //[DonutOutputCache(CacheProfile = "Frequently")]
        public ActionResult _Microblog_Activity(long activityId)
        {
            Activity activity = activityService.Get(activityId);

            if (activity == null)
            {
                return(new EmptyResult());
            }

            MicroblogEntity entity = microBlogService.Get(activity.SourceId);

            ViewData["ActivityId"] = activityId;

            return(View("_Microblog", entity));
        }
예제 #10
0
        public JsonResult Delete(string spaceKey, long microblogId)
        {
            MicroblogEntity microblog = microblogService.Get(microblogId);

            if (!new Authorizer().Microblog_Delete(microblog))
            {
                return(Json(new StatusMessageData(StatusMessageType.Error, "删除失败!"), JsonRequestBehavior.AllowGet));
            }

            long currentUserId = UserContext.CurrentUser.UserId;

            activityServcice.DeleteFromUserInbox(currentUserId, 1);
            microblogService.Delete(microblogId);
            return(Json(new StatusMessageData(StatusMessageType.Success, "删除成功!"), JsonRequestBehavior.AllowGet));
        }
        public AssociatedInfo GetAssociatedInfo(long associateId, string tenantTypeId = "")
        {
            MicroblogService microblogService = new MicroblogService();
            MicroblogEntity  microblog        = microblogService.Get(associateId);

            if (microblog != null)
            {
                IMicroblogUrlGetter urlGetter = MicroblogUrlGetterFactory.Get(microblog.TenantTypeId);
                return(new AssociatedInfo()
                {
                    DetailUrl = urlGetter.MicroblogDetail(microblog.MicroblogId),
                    Subject = HtmlUtility.TrimHtml(microblog.GetResolvedBody(), 16)
                });
            }
            return(null);
        }
예제 #12
0
        /// <summary>
        /// 创建微博
        /// </summary>
        /// <param name="microblog">待创建微博实体</param>
        /// <returns></returns>
        public long Create(MicroblogEntity microblog)
        {
            EventBus <MicroblogEntity> .Instance().OnBefore(microblog, new CommonEventArgs(EventOperationType.Instance().Create()));

            //设置审核状态
            auditService.ChangeAuditStatusForCreate(microblog.UserId, microblog);

            string videoAlias = string.Empty, audioAlias = string.Empty;

            microblog.Body       = parsedMediaService.ResolveBodyForEdit(microblog.Body, out videoAlias, out audioAlias);
            microblog.HasVideo   = !string.IsNullOrEmpty(videoAlias);
            microblog.HasMusic   = !string.IsNullOrEmpty(audioAlias);
            microblog.VideoAlias = videoAlias;
            microblog.AudioAlias = audioAlias;

            long id = 0;

            long.TryParse(microblogRepository.Insert(microblog).ToString(), out id);

            if (id > 0)
            {
                string tenantTypeId = TenantTypeIds.Instance().Microblog();

                OwnerDataService ownerDataService = new OwnerDataService(microblog.TenantTypeId);
                ownerDataService.Change(microblog.OwnerId, OwnerDataKeys.Instance().ThreadCount(), 1);


                //将临时附件转换为正式附件
                attachmentService.ToggleTemporaryAttachments(microblog.UserId, tenantTypeId, id);

                AtUserService atUserService = new AtUserService(tenantTypeId);
                atUserService.ResolveBodyForEdit(microblog.Body, microblog.UserId, microblog.MicroblogId);

                TagService tagService = new TagService(tenantTypeId);
                tagService.ResolveBodyForEdit(microblog.Body, microblog.OwnerId, microblog.MicroblogId, tenantTypeId);

                EventBus <MicroblogEntity> .Instance().OnAfter(microblog, new CommonEventArgs(EventOperationType.Instance().Create()));

                EventBus <MicroblogEntity, AuditEventArgs> .Instance().OnAfter(microblog, new AuditEventArgs(null, microblog.AuditStatus));
            }

            return(id);
        }
예제 #13
0
        /// <summary>
        /// 更新审核状态
        /// </summary>
        /// <param name="microblogId">待被更新的微博Id</param>
        /// <param name="isApproved">是否通过审核</param>
        public void UpdateAuditStatus(long microblogId, bool isApproved)
        {
            MicroblogEntity microblog   = microblogRepository.Get(microblogId);
            AuditStatus     auditStatus = isApproved ? AuditStatus.Success : AuditStatus.Fail;

            if (microblog.AuditStatus == auditStatus)
            {
                return;
            }
            AuditStatus oldAuditStatus = microblog.AuditStatus;

            microblog.AuditStatus = auditStatus;
            microblogRepository.Update(microblog);
            string operationType = isApproved ? EventOperationType.Instance().Approved() : EventOperationType.Instance().Disapproved();

            EventBus <MicroblogEntity> .Instance().OnAfter(microblog, new CommonEventArgs(operationType));

            EventBus <MicroblogEntity, AuditEventArgs> .Instance().OnAfter(microblog, new AuditEventArgs(oldAuditStatus, microblog.AuditStatus));
        }
예제 #14
0
        public ActionResult Detail(string spaceKey, long microblogId)
        {
            GroupEntity group = groupService.Get(spaceKey);

            if (group == null)
            {
                return(HttpNotFound());
            }

            MicroblogEntity entity = microblogService.Get(microblogId);

            if (entity == null)
            {
                return(HttpNotFound());
            }

            pageResourceManager.InsertTitlePart("群组微博详细页");

            ViewData["group"] = group;
            return(View(entity));
        }
예제 #15
0
        /// <summary>
        /// 是否具有删除Microblog的权限
        /// </summary>
        /// <param name="authorizer">被扩展对象</param>
        /// <param name="microblog">微博实体</param>
        /// <returns></returns>
        public static bool Microblog_Delete(this Authorizer authorizer, MicroblogEntity microblog)
        {
            if (microblog == null)
            {
                return(false);
            }

            IUser currentUser = UserContext.CurrentUser;

            if (currentUser == null)
            {
                return(false);
            }

            if (microblog.UserId == currentUser.UserId ||
                authorizer.IsAdministrator(MicroblogConfig.Instance().ApplicationId))
            {
                return(true);
            }

            return(false);
        }
예제 #16
0
        public ActionResult _NewActivity()
        {
            long microblogId = Request.QueryString.Get <long>("microblogId", 0);

            if (microblogId <= 0)
            {
                return(new EmptyResult());
            }
            Activity activity = new ActivityService().Get(TenantTypeIds.Instance().Microblog(), microblogId);

            if (activity == null)
            {
                return(new EmptyResult());
            }
            if (UserContext.CurrentUser == null || activity.UserId != UserContext.CurrentUser.UserId)
            {
                return(new EmptyResult());
            }

            MicroblogEntity entity = microBlogService.Get(activity.SourceId);

            ViewData["ActivityId"] = activity.ActivityId;
            return(View("_Microblog", entity));
        }
예제 #17
0
        /// <summary>
        /// 微博详细显示页
        /// </summary>
        /// <param name="spaceKey"></param>
        /// <param name="microblogId"></param>
        /// <param name="commentId"></param>
        /// <returns></returns>
        public string MicroblogDetail(long microblogId, long?commentId = null)
        {
            string           spaceKey         = string.Empty;
            MicroblogService microblogService = new MicroblogService();
            MicroblogEntity  microblog        = microblogService.Get(microblogId);

            if (microblog == null)
            {
                return(string.Empty);
            }
            else
            {
                if (microblog.OriginalMicroblog != null)
                {
                    microblog = microblog.OriginalMicroblog;
                    if (microblog == null)
                    {
                        return(string.Empty);
                    }
                }
                spaceKey = GroupIdToGroupKeyDictionary.GetGroupKey(microblog.OwnerId);
            }
            return(SiteUrls.Instance().GroupMicroblogDetail(spaceKey, microblogId, commentId));
        }
예제 #18
0
        /// <summary>
        /// 转发微博
        /// </summary>
        /// <param name="microblog">微博实体</param>
        /// <param name="isCommnet">是否对被转发微博进行评论</param>
        /// <param name="isCommentOriginal">是否对微博原文进行评论</param>
        /// <param name="toUserId">评论拥有者Id</param>
        /// <param name="toOriginalUserId">源引微博评论拥有者Id</param>
        /// <param name="microblogId">返回新的microblogId</param>
        /// <returns>是否创建成功,成功为-true</returns>
        public bool Forward(MicroblogEntity microblog, bool isCommnet, bool isCommentOriginal, long toUserId, long toOriginalUserId, out long microblogId)
        {
            microblogId = Create(microblog);
            bool isSuccess = microblogId > 0;

            if (!isSuccess)
            {
                return(isSuccess);
            }

            if (isCommnet)
            {
                Comment comment = Comment.New();
                comment.UserId            = microblog.UserId;
                comment.TenantTypeId      = TenantTypeIds.Instance().Microblog();
                comment.CommentedObjectId = microblog.ForwardedMicroblogId;
                comment.OwnerId           = toUserId;
                comment.Author            = microblog.Author;
                comment.Body = microblog.Body;
                commentService.Create(comment);
            }

            if (isCommentOriginal)
            {
                Comment comment = Comment.New();
                comment.UserId            = microblog.UserId;
                comment.TenantTypeId      = TenantTypeIds.Instance().Microblog();
                comment.CommentedObjectId = microblog.OriginalMicroblogId;
                comment.OwnerId           = toOriginalUserId;
                comment.Author            = microblog.Author;
                comment.Body = microblog.Body;
                commentService.Create(comment);
            }

            return(isSuccess);
        }
        public ActionResult _Detail(string spaceKey, long microblogId)
        {
            MicroblogEntity entity = microblogService.Get(microblogId);

            return(View(entity));
        }
예제 #20
0
        /// <summary>
        /// 更新索引
        /// </summary>
        /// <param name="microblog">待更新的微博</param>
        public void Update(MicroblogEntity microblog)
        {
            Document doc = MicroblogIndexDocument.Convert(microblog);

            searchEngine.Update(doc, microblog.MicroblogId.ToString(), MicroblogIndexDocument.MicroblogId);
        }
예제 #21
0
 /// <summary>
 /// 添加索引
 /// </summary>
 /// <param name="microblog">待添加的微博</param>
 public void Insert(MicroblogEntity microblog)
 {
     Insert(new MicroblogEntity[] { microblog });
 }
        /// <summary>
        /// 转发微博控件
        /// </summary>
        public ActionResult _ForwardMicroblog(string spaceKey, long microblogId)
        {
            MicroblogEntity microblogEntity = microblogService.Get(microblogId);

            return(View(microblogEntity));
        }
        public ActionResult Create(string spaceKey, string microblogBody, string tenantTypeId = null, long ownerId = 0, string imageUrl = null)
        {
            if (string.IsNullOrEmpty(microblogBody))
            {
                return(Json(new { MessageType = StatusMessageType.Error, MessageContent = "内容不能为空!" }));
            }
            if (!ValidateContentLength(microblogBody))
            {
                return(Json(new { MessageType = StatusMessageType.Error, MessageContent = "内容不能超过140个字!" }));
            }

            //当前用户登录
            IUser currentUser = UserContext.CurrentUser;

            bool            isBanned = ModelState.HasBannedWord();
            MicroblogEntity entity   = MicroblogEntity.New();

            entity.Author       = currentUser.DisplayName;
            entity.Body         = Tunynet.Utilities.WebUtility.HtmlEncode(microblogBody);
            entity.PostWay      = PostWay.Web;
            entity.TenantTypeId = !string.IsNullOrEmpty(tenantTypeId) ? tenantTypeId : TenantTypeIds.Instance().User();
            entity.UserId       = currentUser.UserId;
            entity.OwnerId      = ownerId > 0 ? ownerId : currentUser.UserId;

            if (!authorizer.Microblog_Create(entity.TenantTypeId, entity.OwnerId))
            {
                return(HttpNotFound());
            }

            //判断是否当前有,图片附件
            HttpCookie cookie = Request.Cookies["microblog_PhotoExists"];

            if (cookie != null && cookie.Value.Trim().ToLower().Equals("true"))
            {
                entity.HasPhoto = true;
                cookie.Value    = "";
                Response.Cookies.Set(cookie);
            }

            if (!string.IsNullOrEmpty(imageUrl))
            {
                //by zhaoyx:获取到的图片地址如果带有“-”字符的话,会被ModelBinder屏蔽掉,导致图片无法加载
                imageUrl        = Request["imageUrl"];
                entity.HasPhoto = true;
            }

            bool isSuccess = false;

            if (!isBanned)
            {
                isSuccess = microblogService.Create(entity) > 0;
            }

            //by zhengw:
            if (isSuccess)
            {
                //处理imageUrl
                if (!string.IsNullOrEmpty(imageUrl))
                {
                    DownloadRemoteImage(imageUrl, entity.MicroblogId);
                }

                //同步微博
                var accountBindingService = new AccountBindingService();
                foreach (var accountType in accountBindingService.GetAccountTypes(true, true))
                {
                    bool isSync = Request.Form.GetBool("sync_" + accountType.AccountTypeKey, false);
                    if (isSync)
                    {
                        var account = accountBindingService.GetAccountBinding(currentUser.UserId, accountType.AccountTypeKey);
                        if (account != null)
                        {
                            var thirdAccountGetter = ThirdAccountGetterFactory.GetThirdAccountGetter(accountType.AccountTypeKey);
                            if (entity.HasPhoto)
                            {
                                byte[] bytes       = null;
                                var    attachments = attachmentService.GetsByAssociateId(entity.MicroblogId);
                                string fileName    = null;
                                if (attachments.Count() > 0)
                                {
                                    var            attachment    = attachments.First();
                                    IStoreProvider storeProvider = DIContainer.Resolve <IStoreProvider>();
                                    IStoreFile     storeFile     = storeProvider.GetResizedImage(attachment.GetRelativePath(), attachment.FileName, new Size(405, 600), Tunynet.Imaging.ResizeMethod.KeepAspectRatio);
                                    using (Stream stream = storeFile.OpenReadStream())
                                    {
                                        bytes = StreamToBytes(stream);
                                        stream.Dispose();
                                        stream.Close();
                                    }
                                    fileName = attachment.FriendlyFileName;
                                }
                                thirdAccountGetter.CreatePhotoMicroBlog(account.AccessToken, microblogBody, bytes, fileName, account.Identification);
                            }
                            else
                            {
                                thirdAccountGetter.CreateMicroBlog(account.AccessToken, microblogBody, account.Identification);
                            }
                        }
                    }
                }
                if ((int)entity.AuditStatus > (int)(new AuditService().GetPubliclyAuditStatus(MicroblogConfig.Instance().ApplicationId)))
                {
                    return(Json(new { MessageType = StatusMessageType.Success, MessageContent = "发布成功", id = entity.MicroblogId }));
                }
                else
                {
                    return(Json(new { MessageType = StatusMessageType.Hint, MessageContent = "尚未通过审核,请耐心等待", id = entity.MicroblogId }));
                }
            }

            if (isBanned)
            {
                return(Json(new { MessageType = StatusMessageType.Error, MessageContent = "内容中有非法词语!" }));
            }
            else
            {
                return(Json(new { MessageType = StatusMessageType.Error, MessageContent = "创建失败请联系管理员!" }));
            }
        }
예제 #24
0
        public ActionResult Comment(MicroblogCommentEditModel model)
        {
            string message = string.Empty;

            if (ModelState.HasBannedWord(out message))
            {
                return(Json(new StatusMessageData(StatusMessageType.Error, message)));
            }

            IUser currentUser = UserContext.CurrentUser;
            long  userId      = microblogService.Get(model.CommentedObjectId).UserId;

            //被评论用户的隐私判断

            if (!privacyService.Validate(userId, currentUser != null ? currentUser.UserId : 0, PrivacyItemKeys.Instance().Comment()))
            {
                return(Json(new StatusMessageData(StatusMessageType.Hint, "该用户不允许你评论他的内容!")));
            }

            CommentService commentService = new CommentService();

            if (model.IsValidate)
            {
                Comment comment = model.AsComment();

                if (comment.ParentId != 0)
                {
                    Comment parentComment = commentService.Get(comment.ParentId);
                    if (parentComment != null)
                    {
                        comment.IsPrivate = parentComment.IsPrivate ? true : comment.IsPrivate;
                    }
                }

                if (commentService.Create(comment))
                {
                    if (model.CommentOriginalAuthor)
                    {
                        MicroblogEntity entity = microblogService.Get(comment.CommentedObjectId);


                        if (entity != null)
                        {
                            Comment originalAuthorComment = model.AsComment();
                            entity = entity.OriginalMicroblog;
                            if (entity != null)
                            {
                                originalAuthorComment.ToUserId          = entity.UserId;
                                originalAuthorComment.ToUserDisplayName = entity.User.DisplayName;
                                originalAuthorComment.CommentedObjectId = entity.MicroblogId;
                                commentService.Create(originalAuthorComment);
                            }
                        }
                    }
                    if (model.ForwardMicrobo)
                    {
                        MicroblogEntity microblogEntity = microblogService.Get(model.CommentedObjectId);
                        if (microblogEntity != null)
                        {
                            MicroblogEntity microblog = MicroblogEntity.New();
                            microblog.Body         = "转发微博";
                            microblog.Author       = currentUser.DisplayName;
                            microblog.UserId       = currentUser.UserId;
                            microblog.OwnerId      = currentUser.UserId;
                            microblog.TenantTypeId = TenantTypeIds.Instance().User();

                            microblog.ForwardedMicroblogId = microblogEntity.MicroblogId;
                            microblog.OriginalMicroblogId  = microblogEntity.OriginalMicroblogId > 0 ? microblogEntity.OriginalMicroblogId : microblog.ForwardedMicroblogId;

                            long toUserId = microblog.UserId;

                            MicroblogEntity entity           = microblogService.Get(microblog.OriginalMicroblogId);
                            long            toOriginalUserId = entity == null ? 0 : entity.UserId;

                            microblogService.Forward(microblog, false, false, toUserId, toOriginalUserId);
                        }
                    }
                    return(Json(new { commentid = comment.Id }));
                }
            }
            WebUtility.SetStatusCodeForError(Response);
            return(Json(new StatusMessageData(StatusMessageType.Error, "创建留言失败了!")));
        }
예제 #25
0
 public ActionResult _ShowMicroblogInList(MicroblogEntity entity)
 {
     return(View(entity));
 }
예제 #26
0
        public ActionResult _Microblog(long microblogId)
        {
            MicroblogEntity microblog = microBlogService.Get(microblogId);

            return(View(microblog));
        }