public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "application/json";

            string accountId = context.Request.Params["accountId"];
            string content = context.Request.Params["content"];
            string KillingId = context.Request.Params["KillingId"];
            try
            {
                if (accountId != null && content != null && KillingId != null)
                {
                    CY.UME.Core.Business.SpaceComment scomment = new CY.UME.Core.Business.SpaceComment();
                    scomment.InstanceId = long.Parse(KillingId);
                    scomment.AuthorId = long.Parse(accountId);
                    scomment.AccountId = 0;
                    scomment.Content = content;
                    scomment.DateCreated = DateTime.Now;
                    scomment.ReferedId = 0;
                    scomment.IsPublic = true;
                    scomment.IP = CY.Utility.Common.RequestUtility.ClientIP;
                    scomment.Save();

                    CY.UME.Core.Business.SpaceCommentExtend scommentex = new CY.UME.Core.Business.SpaceCommentExtend();
                    scommentex.Id = scomment.Id;
                    scommentex.InstanceId = KillingId;
                    scommentex.Type = "Killing";
                    scommentex.AccountId = 0;
                    scommentex.Save();

                    context.Response.Write("{success:true,Time:'" + scomment.DateCreated.ToString("yyyy-MM-dd HH:mm:ss") + "'}");
                }
                else
                {
                    context.Response.Write("{success:false}");
                }
            }
            catch
            {
                context.Response.Write("{success:false}");
            }
        }
Exemple #2
0
        /// <summary>
        ///  0 登录失败 -1请求失败 -2系统错误 1成功
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public string LeaveWords(HttpContext context)
        {
            string email;
            string content;
            long accountId = 0;
            CY.UME.Core.Business.Account spaceAccount;
            CY.UME.Core.Business.AccountExtend accountExtend;

            #region validate

            if (context.Request.QueryString["AccountId"] == null
                || !long.TryParse(context.Request.QueryString["AccountId"].ToString(), out accountId)
                || context.Request.QueryString["Content"]==null
                || context.Request.QueryString["email"]==null)
            {
                return "-1";
            }

            content = context.Request.QueryString["Content"].ToString().Trim();

            spaceAccount = CY.UME.Core.Business.Account.Load(accountId);

            email = context.Request.QueryString["email"].ToString().Trim();

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

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

            try
            {
                CY.UME.Core.Business.SpaceComment spaceComment = new CY.UME.Core.Business.SpaceComment();

                spaceComment.AccountId = spaceAccount.Id;
                spaceComment.AuthorId = accountExtend.Id;
                spaceComment.Content = context.Server.UrlDecode(content);
                spaceComment.DateCreated = DateTime.Now;
                spaceComment.IsPublic = true;
                spaceComment.Save();

                if (accountExtend.Id != spaceAccount.Id)
                {
                    CY.UME.Core.Business.Notice notice = new CY.UME.Core.Business.Notice();

                    notice.AccountId = spaceAccount.Id;
                    notice.AuthorId = accountExtend.Id;
                    notice.Content = "给您留言了";
                    notice.DateCreated = DateTime.Now;
                    notice.InstanceId = spaceComment.Id.ToString();
                    notice.IsReaded = false;
                    notice.Type = "inforeply";
                    notice.Save();
                }

                return spaceComment.Id.ToString();
            }
            catch
            {
                return "-2";
            }
        }
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "application/json";
            try
            {
                long instanceId; // 空间用户的标识 || 群Id
                long referedId; // 回复留言的标识
                string content;
                string type = String.Empty;//类型(SpaceCommentExtend)
                CY.UME.Core.Business.Account currentAccount; // 留言的用户
                CY.UME.Core.Business.Account spaceAccount = new CY.UME.Core.Business.Account(); // 所在个人主页的用户
                CY.UME.Core.Business.SpaceComment referedComment = new CY.UME.Core.Business.SpaceComment(); // 所回复的留言
                CY.UME.Core.Business.SpaceComment comment = new CY.UME.Core.Business.SpaceComment(); // 留言
                CY.UME.Core.Business.Group group = new CY.UME.Core.Business.Group();//群组
                CY.UME.Core.Business.Activities active = new CY.UME.Core.Business.Activities();//活动

                #region Validateion and Get Basic Data

                if (!CY.Utility.Common.ParseUtility.TryParseInt64(context.Request.Form["uid"], out instanceId) ||
                    !CY.Utility.Common.ParseUtility.TryParseInt64(context.Request.Form["referedId"], out referedId))
                {
                    context.Response.Write("{success:false,msg:'参数错误'}");
                    return;
                }

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

                currentAccount = CY.UME.Core.Global.GetCurrentAccount();
                if (currentAccount == null)
                {
                    context.Response.Write("{success:false,msg:'登录超时,请重新登录'}");
                    return;
                }

                // 所在个人主页的用户
                if (instanceId == 0 && type.Length == 0)
                {
                    instanceId = currentAccount.Id;
                    spaceAccount = currentAccount;
                }
                else if (type.Length == 0)
                {
                    spaceAccount = CY.UME.Core.Business.Account.Load(instanceId);

                    if (spaceAccount == null)
                    {
                        context.Response.Write("{success:false,msg:'用户不存在'}");
                        return;
                    }
                }
                else if (type == "group")
                {
                    group = CY.UME.Core.Business.Group.Load((int)instanceId);

                    if (group == null)
                    {
                        context.Response.Write("{success:false,msg:'该群组不存在或已被删除'}");
                        return;
                    }
                }
                else if (type == "active")
                {
                    active = CY.UME.Core.Business.Activities.Load((int)instanceId);
                    if (active == null)
                    {
                        context.Response.Write("{success:false,msg:'该活动不存在或已被删除'}");
                        return;
                    }
                }

                // 所回复的留言
                if (referedId > 0)
                {
                    referedComment = CY.UME.Core.Business.SpaceComment.Load(referedId);
                    if (referedComment == null)
                    {
                        context.Response.Write("{success:false,msg:'所回复的留言已被删除'}");
                        return;
                    }
                }

                // 留言内容
                content = context.Request.Form["content"];
                if (string.IsNullOrEmpty(content))
                {
                    context.Response.Write("{success:false,msg:'留言内容不能为空'}");
                    return;
                }

                #endregion

                #region Leave Msg,Notice

                if (type.Length == 0)//个人空间留言
                {
                    // 将留言或者回复信息发送给空间主人
                    comment.AccountId = spaceAccount.Id;
                    comment.Content = content;
                    comment.IsPublic = (context.Request.Form["isPublic"] == "0") ? false : true;
                    comment.ReferedId = referedId;
                    comment.AuthorId = currentAccount.Id;
                    comment.DateCreated = DateTime.Now;
                    comment.InstanceId = 0;
                    comment.IP = CY.Utility.Common.RequestUtility.ClientIP;
                    comment.Save();

                    if (spaceAccount.Id != currentAccount.Id) // 不是在自己空间,留言则通知空间主人,回复则通知所回复的留言的作者
                    {
                        CY.UME.Core.Business.Notice notice = new CY.UME.Core.Business.Notice();
                        notice.AuthorId = comment.AuthorId;
                        notice.IsReaded = false;
                        notice.DateCreated = DateTime.Now;
                        notice.InstanceId = comment.Id.ToString();

                        if (comment.ReferedId < 1) // 留言
                        {
                            notice.Type = "info";
                            notice.AccountId = instanceId;
                            //notice.Content = currentAccount.Name + "给您留言了";
                            notice.Content = "给您留言了";
                            notice.Save();
                        }
                        else // 回复
                        {
                            if (referedComment.Id > 0)
                            {
                                notice.Type = "inforeply";
                                notice.AccountId = referedComment.AuthorId;

                                if (referedComment.AuthorId == spaceAccount.Id) // 回复空间主人
                                {
                                    //notice.Content = currentAccount.Name + "回复了您的留言";
                                    notice.Content = "回复了您的留言";
                                }
                                else // 在别人页面回复了另外一个人
                                {
                                    //notice.Content = currentAccount.Name + "回复了您在 " + spaceAccount.Name + " 处的留言";
                                    notice.Content = "回复了您在 " + spaceAccount.Name + " 处的留言";

                                    // 在所引用的留言的作者处添加一条回复副本
                                    CY.UME.Core.Business.SpaceComment commentCopy = new CY.UME.Core.Business.SpaceComment();
                                    commentCopy.AccountId = referedComment.AuthorId;
                                    commentCopy.AuthorId = currentAccount.Id;
                                    commentCopy.Content = comment.Content;
                                    commentCopy.DateCreated = comment.DateCreated;
                                    commentCopy.InstanceId = comment.InstanceId;
                                    commentCopy.IP = comment.IP;
                                    commentCopy.IsPublic = comment.IsPublic;
                                    commentCopy.ReferedId = comment.ReferedId;
                                    commentCopy.Save();

                                    notice.InstanceId = commentCopy.Id.ToString();
                                }
                                notice.Save();
                            }
                        }
                    }
                    else // 在自己空间内
                    {
                        if (referedComment.Id > 0 && referedComment.AuthorId != currentAccount.Id) // 为回复他人
                        {
                            CY.UME.Core.Business.Notice notice = new CY.UME.Core.Business.Notice();
                            notice.AuthorId = comment.AuthorId;
                            notice.IsReaded = false;
                            notice.DateCreated = DateTime.Now;
                            notice.Type = "inforeply";
                            notice.AccountId = referedComment.AuthorId;
                            //notice.Content = currentAccount.Name + "回复了您的留言";
                            notice.Content = "回复了您的留言";

                            // 在所引用的留言的作者处添加一条回复副本,方便其在他的个人空间内查看到
                            CY.UME.Core.Business.SpaceComment commentCopy = new CY.UME.Core.Business.SpaceComment();
                            commentCopy.AccountId = referedComment.AuthorId;
                            commentCopy.AuthorId = currentAccount.Id;
                            commentCopy.Content = comment.Content;
                            commentCopy.DateCreated = comment.DateCreated;
                            commentCopy.InstanceId = comment.InstanceId;
                            commentCopy.IP = comment.IP;
                            commentCopy.IsPublic = comment.IsPublic;
                            commentCopy.ReferedId = comment.ReferedId;
                            commentCopy.Save();

                            notice.InstanceId = commentCopy.Id.ToString();
                            notice.Save();
                        }
                    }
                }
                else if (type == "group")//群留言
                {
                    //保存留言
                    comment.AuthorId = currentAccount.Id;
                    comment.AccountId = 0;
                    comment.Content = content;
                    comment.DateCreated = DateTime.Now;
                    comment.InstanceId = group.Id;
                    comment.IP = CY.Utility.Common.RequestUtility.ClientIP;
                    comment.IsPublic = true;
                    comment.ReferedId = referedId;

                    comment.Save();

                    //保存到留言扩展信息
                    CY.UME.Core.Business.SpaceCommentExtend spaceCommentExtend = new CY.UME.Core.Business.SpaceCommentExtend();

                    spaceCommentExtend.AccountId = group.CreatorId;
                    spaceCommentExtend.Id = comment.Id;
                    spaceCommentExtend.InstanceId = group.Id.ToString();
                    spaceCommentExtend.Type = "group";

                    spaceCommentExtend.Save();

                    //留言回复通知
                    if (referedId > 0 && referedComment.AuthorId != currentAccount.Id)
                    {
                        CY.UME.Core.Business.Notice groupLeaveWordsNotice = new CY.UME.Core.Business.Notice();

                        groupLeaveWordsNotice.AccountId = referedComment.AuthorId;
                        groupLeaveWordsNotice.AuthorId = comment.AuthorId;
                        groupLeaveWordsNotice.Content = "回复了您的留言";
                        groupLeaveWordsNotice.DateCreated = DateTime.Now;
                        groupLeaveWordsNotice.InstanceId = comment.InstanceId.ToString();
                        groupLeaveWordsNotice.IsReaded = false;
                        groupLeaveWordsNotice.Type = "groupinforeply";

                        groupLeaveWordsNotice.Save();
                    }
                }
                else if (type == "active")//活动留言
                {
                    //保存留言
                    comment.AuthorId = currentAccount.Id;
                    comment.AccountId = active.Sponsor;
                    comment.Content = content;
                    comment.DateCreated = DateTime.Now;
                    comment.InstanceId = active.Id;
                    comment.IP = CY.Utility.Common.RequestUtility.ClientIP;
                    comment.IsPublic = true;
                    comment.ReferedId = referedId;

                    comment.Save();

                    //保存到留言扩展信息
                    CY.UME.Core.Business.SpaceCommentExtend spaceCommentExtend = new CY.UME.Core.Business.SpaceCommentExtend();

                    spaceCommentExtend.AccountId = active.Sponsor;
                    spaceCommentExtend.Id = comment.Id;
                    spaceCommentExtend.InstanceId = active.Id.ToString();
                    spaceCommentExtend.Type = "active";

                    spaceCommentExtend.Save();

                    //留言回复通知
                    if (referedId > 0 && referedComment.AuthorId != currentAccount.Id)
                    {
                        CY.UME.Core.Business.Notice groupLeaveWordsNotice = new CY.UME.Core.Business.Notice();

                        groupLeaveWordsNotice.AccountId = referedComment.AuthorId;
                        groupLeaveWordsNotice.AuthorId = comment.AuthorId;
                        groupLeaveWordsNotice.Content = "回复了您的留言";
                        groupLeaveWordsNotice.DateCreated = DateTime.Now;
                        groupLeaveWordsNotice.InstanceId = comment.InstanceId.ToString();
                        groupLeaveWordsNotice.IsReaded = false;
                        groupLeaveWordsNotice.Type = "activeinforeply";

                        groupLeaveWordsNotice.Save();
                    }
                }
                #endregion

                StringBuilder sb = new StringBuilder();
                sb.Append("{success:true, msg: '添加成功!', account: {");
                sb.Append("Id: " + comment.AuthorId);
                sb.Append(", Name: '");
                sb.Append(currentAccount.Name);
                sb.Append("'}, commentId: ");
                sb.Append(comment.Id);
                sb.Append("}");

                context.Response.Write(sb.ToString());
            }
            catch (Exception ex)
            {
                context.Response.Write("{success:false, msg:'添加失败!错误信息:" + CY.Utility.Common.StringUtility.RemoveIllegalCharacters(ex.Message) + "'}");
            }
        }