public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "application/json";
            CY.UME.Core.Business.Account account;
            CY.UME.Core.Business.MiniBlog miniBlog;
            long miniBlogId = 0;
            string content = String.Empty;
            string strReplyedId = String.Empty;

            #region validate
            if (context.Request.Form["MiniBlogId"] == null ||
                !long.TryParse(context.Request.Form["MiniBlogId"].ToString(), out miniBlogId))
            {
                context.Response.Write("{success:false,msg:'操作失败'}");
                return;
            }

            if (context.Request.Form["Content"] != null)
            {
                content = context.Request.Form["Content"].ToString().Trim();
                content = Utility.Common.StringUtility.HTMLEncode(content);
                content = Regex.Replace(content, @"(http:\/\/[\w.]+\/?)([^\u4e00-\u9fa5|\u0020]*)", "<a href=\"$1$2\">$1$2</a>", RegexOptions.IgnoreCase | RegexOptions.Multiline);
            }

            if (context.Request.Form["strReplyedMinBlogId"] != null)
            {
                strReplyedId = context.Request.Form["strReplyedMinBlogId"].ToString().Trim();
            }

            account = CY.UME.Core.Global.GetCurrentAccount();

            if (account == null)
            {
                context.Response.Write("{success:false,msg:'登录超时失败'}");
                return;
            }

            miniBlog = CY.UME.Core.Business.MiniBlog.Load(miniBlogId);

            if (miniBlog == null)
            {
                context.Response.Write("{success:false,msg:'参数错误'}");
                return;
            }

            if (account.Id == miniBlog.AccountId)
            {
                context.Response.Write("{success:false,msg:'不能转发自己的博文'}");
                return;
            }

            CY.UME.Core.Business.Account accountRefered = CY.UME.Core.Business.Account.Load(miniBlog.AccountId);

            if (accountRefered == null)
            {
                context.Response.Write("{success:false,msg:'您无法转发该篇博文'}");
                return;
            }

            if (miniBlog.HasTransedByThisAccount(account))
            {
                context.Response.Write("{success:false,msg:'您已经转发过该篇博文'}");
                return;
            }
            #endregion
            try
            {
                CY.UME.Core.Business.MiniBlog newMiniBlog = new CY.UME.Core.Business.MiniBlog();

                newMiniBlog.AccountId = account.Id;
                newMiniBlog.Content = content;
                newMiniBlog.DatePublish = DateTime.Now;
                newMiniBlog.IP = CY.Utility.Common.RequestUtility.ClientIP;

                newMiniBlog.Save();

                string imgPath = String.Empty;
                string flashPath = String.Empty;
                CY.UME.Core.Business.MiniBlogExtend miniBlogExtend = CY.UME.Core.Business.MiniBlogExtend.Load(miniBlog.Id);
                if (miniBlogExtend != null)
                {
                    imgPath = miniBlogExtend.ImgPath;
                    flashPath = miniBlogExtend.Video;
                }

                CY.UME.Core.Business.MiniBlogExtend newMiniBlogExtend = new CY.UME.Core.Business.MiniBlogExtend();

                newMiniBlogExtend.AccountId = newMiniBlog.AccountId;
                newMiniBlogExtend.Id = newMiniBlog.Id;
                newMiniBlogExtend.ImgPath = imgPath;
                newMiniBlogExtend.Video = flashPath;
                newMiniBlogExtend.IsMsgReceived = false;
                newMiniBlogExtend.IsPhoneSended = false;
                newMiniBlogExtend.ReferedId = miniBlog.Id;
                newMiniBlogExtend.ReferedName = accountRefered.Name;
                newMiniBlogExtend.ReferedAuthorId = accountRefered.Id;
                newMiniBlogExtend.TransferedNum = 0;

                newMiniBlogExtend.Save();

                account.SendNoticeToAllFriendAndFollower("miniblog", "转发了一篇微博", newMiniBlog.Id.ToString());

                CY.UME.Core.Business.Notice notice = new CY.UME.Core.Business.Notice();

                notice.AccountId = newMiniBlogExtend.AccountId;
                notice.AuthorId = newMiniBlogExtend.AccountId;
                notice.Content = "转发了一篇微博";
                notice.DateCreated = DateTime.Now;
                notice.InstanceId = newMiniBlogExtend.Id.ToString();
                notice.IsReaded = false;
                notice.Type = "miniblog";
                notice.Save();

                #region Reply
                string strReplyedIdTemp = String.Empty;
                string[] arrReplyedId = strReplyedId.Split(',');

                for (int i = 0; i < arrReplyedId.Length; i++)
                {
                    strReplyedIdTemp = arrReplyedId[i];

                    long replyedId = 0;
                    if (long.TryParse(strReplyedIdTemp, out replyedId))
                    {
                        CY.UME.Core.Business.MiniBlog replyedMiniBlog = CY.UME.Core.Business.MiniBlog.Load(replyedId);

                        if (replyedMiniBlog != null)
                        {
                            CY.UME.Core.Business.MiniBlogComment mbc = new CY.UME.Core.Business.MiniBlogComment();

                            mbc.AccountId = replyedMiniBlog.AccountId;
                            mbc.AuthorId = account.Id;
                            mbc.Content = content;
                            mbc.DateCreated = DateTime.Now;
                            mbc.IP = Utility.Common.RequestUtility.ClientIP;
                            mbc.InstanceId = replyedMiniBlog.Id;

                            mbc.Save();

                            CY.UME.Core.Business.Notice noticeTemp = new CY.UME.Core.Business.Notice();

                            noticeTemp.AccountId = replyedMiniBlog.AccountId;
                            noticeTemp.AuthorId = mbc.AuthorId;
                            noticeTemp.Content = "评论了您的微博";
                            noticeTemp.DateCreated = DateTime.Now;
                            noticeTemp.InstanceId = replyedId.ToString();
                            noticeTemp.IsReaded = false;
                            noticeTemp.Type = "miniblogreply";

                            noticeTemp.Save();
                        }
                    }
                }
                #endregion

                context.Response.Write("{success:true}");
            }
            catch
            {
                context.Response.Write("{success:false,msg:'服务器忙,请稍后再试'}");
            }
        }
示例#2
0
        /// <summary>
        /// 0登录失败 -1 请求失败 -2异常错误 -3该微博不存在或已被删除 -4 您无法转发自己的微博
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public string TransferMiniBlog(HttpContext context)
        {
            long miniBlogId = 0;
            string email = String.Empty;
            CY.UME.Core.Business.AccountExtend accountExtend;
            CY.UME.Core.Business.MiniBlog miniBlog;
            CY.UME.Core.Business.Account account;

            #region validate
            if (context.Request.QueryString["email"] == null
                || context.Request.QueryString["MiniBlogId"] == null
                || !long.TryParse(context.Request.QueryString["MiniBlogId"].ToString(), out miniBlogId))
            {
                return "-1";
            }
            email = context.Request.QueryString["email"].ToString();

            accountExtend = CY.UME.Core.Business.AccountExtend.Load(email);

            if (accountExtend == null)
            {
                return "-1";
            }

            account = CY.UME.Core.Business.Account.Load(accountExtend.Id);

            miniBlog = CY.UME.Core.Business.MiniBlog.Load(miniBlogId);

            if (miniBlog == null)
            {
                return "-3";
            }

            if (miniBlog.AccountId == accountExtend.Id)
            {
                return "-4";
            }

            CY.UME.Core.Business.Account refAccount = CY.UME.Core.Business.Account.Load(miniBlog.AccountId);

            #endregion

            CY.UME.Core.Business.MiniBlog newMiniBlog = new CY.UME.Core.Business.MiniBlog();

            newMiniBlog.AccountId = accountExtend.Id;
            newMiniBlog.Content = miniBlog.Content;
            newMiniBlog.DatePublish = DateTime.Now;
            newMiniBlog.IP = CY.Utility.Common.RequestUtility.ClientIP;

            newMiniBlog.Save();

            string imgPath = String.Empty;
            CY.UME.Core.Business.MiniBlogExtend miniBlogExtend = CY.UME.Core.Business.MiniBlogExtend.Load(miniBlog.Id);
            if (miniBlogExtend != null)
            {
                imgPath = miniBlogExtend.ImgPath;
            }

            CY.UME.Core.Business.MiniBlogExtend newMiniBlogExtend = new CY.UME.Core.Business.MiniBlogExtend();

            newMiniBlogExtend.AccountId = newMiniBlog.AccountId;
            newMiniBlogExtend.Id = newMiniBlog.Id;
            newMiniBlogExtend.ImgPath = imgPath;
            newMiniBlogExtend.IsMsgReceived = false;
            newMiniBlogExtend.IsPhoneSended = false;
            newMiniBlogExtend.ReferedId = miniBlog.Id;
            newMiniBlogExtend.ReferedName = refAccount == null ? "用户已被删除" : refAccount.Name;
            newMiniBlogExtend.TransferedNum = 0;

            newMiniBlogExtend.Save();

            account.SendNoticeToAllFriendAndFollower("miniblog", "转发了一篇微博", newMiniBlog.Id.ToString());

            return newMiniBlog.Id.ToString();
        }