public void ProcessRequest(HttpContext context) { context.Response.ContentType = "application/json"; long spaceId; // 空间用户的标识 long referedId; // 回复留言的标识 long InstanceId; string content; CY.UME.Core.Business.Account currentAccount; // 留言的用户 CY.UME.Core.Business.Account spaceAccount; // 所在个人主页的用户 CY.UME.Core.Business.BlogComment comment = new CY.UME.Core.Business.BlogComment(); CY.UME.Core.Business.BlogComment referedComment = new CY.UME.Core.Business.BlogComment(); // 所回复的留言 //spaceId--空间Id,referedId--日志评论Id,InstanceId--日志Id if (!CY.Utility.Common.ParseUtility.TryParseInt64(context.Request.Form["spaceId"], out spaceId) || !CY.Utility.Common.ParseUtility.TryParseInt64(context.Request.Form["referedId"], out referedId) || !CY.Utility.Common.ParseUtility.TryParseInt64(context.Request.Form["InstanceId"], out InstanceId)) { context.Response.Write("{success:false,msg:'参数错误'}"); return; } currentAccount = CY.UME.Core.Global.GetCurrentAccount(); if (currentAccount == null) { context.Response.Write("{success:false,msg:'登录超时,请重新登录'}"); return; } // 所在个人主页的用户 if (spaceId == 0) { spaceId = currentAccount.Id; spaceAccount = currentAccount; } else { spaceAccount = CY.UME.Core.Business.Account.Load(spaceId); if (spaceAccount == null) { context.Response.Write("{success:false,msg:'用户不存在'}"); return; } } //添加评论 CY.UME.Core.Business.Blog blog = CY.UME.Core.Business.Blog.Load(InstanceId); blog.ReplyNum++; blog.Save(); // 所回复的留言 if (referedId > 0) { referedComment = CY.UME.Core.Business.BlogComment.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; } #region Leave Msg,Notice // 将留言或者回复信息发送给空间主人 comment.AccountId = spaceAccount.Id; comment.Content = content; comment.ReferedId = referedId; comment.AuthorId = currentAccount.Id; comment.DateCreated = DateTime.Now; comment.InstanceId = InstanceId; 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 = blog.Id.ToString(); notice.Type = "blogreply"; if (referedComment.Id > 0) { notice.AccountId = referedComment.AuthorId; if (referedComment.AuthorId == spaceAccount.Id) //回复空间主人 { notice.Content = "评论了您的日志"; } else // 在别人的日志处回复了另外一个人 { notice.Content = "回复了您的评论"; } } else { notice.AccountId = spaceAccount.Id; notice.Content = "评论了您的日志"; } 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 = "blogreply"; notice.AccountId = referedComment.AuthorId; notice.Content = currentAccount.Name + "回复了您的评论"; notice.InstanceId = blog.Id.ToString(); notice.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()); }
public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/plain"; //变量 HttpPostedFile imgFile; int groupId = 0; long accountId = 0; long albumId = 0; string noticeContent = String.Empty; string gId = ""; string alId = ""; string aId = ""; noticeContent = context.Request.QueryString["noticeContent"].ToString().Trim(); aId = context.Request.QueryString["accountId"].ToString(); alId = context.Request.QueryString["albumId"].ToString(); gId = context.Request.QueryString["groupId"].ToString(); if (context.Request.QueryString["noticeContent"] != null) { noticeContent = context.Server.UrlDecode(noticeContent); } if (!long.TryParse(aId, out accountId)) { return; } if (!long.TryParse(alId, out albumId)) { return; } if (!int.TryParse(gId, out groupId)) { return; } CY.UME.Core.Business.Account account = CY.UME.Core.Business.Account.Load(accountId); if (account == null) { return; } if (account.Id == 0) { context.Response.Write("用户登录超时,请重新登录"); return; } CY.UME.Core.Business.Group group = CY.UME.Core.Business.Group.Load(groupId); if (group == null) { return; } if (group.AddPicturePermission == 1 && !group.CheckIsGroupMember(account)) { return; } else if (group.AddPicturePermission == 2 && !group.CheckIsManager(account)) { return; } CY.UME.Core.Business.Album album = CY.UME.Core.Business.Album.Load(albumId); if (album == null || album.Id == 0) { album = group.CreateGroupAlbum(); } //获取上传的文件并保存 if (context.Request.Files.Count > 0) { imgFile = context.Request.Files[0]; if (imgFile == null) { return; } string imgExtention = CY.Utility.Common.FileUtility.GetFileExtension(imgFile.FileName).ToLower(); string imgName = CY.Utility.Common.FileUtility.GetFileName(imgFile.FileName); string appPath = CY.Utility.Common.RequestUtility.CurPhysicalApplicationPath; string dirPath = appPath + "/Content/Group/Album/" + groupId + "/"; string fileName = "/Content/Group/Album/" + groupId + "/" + DateTime.Now.ToString("yyyMMddhhmmss") + DateTime.Now.Millisecond.ToString();//相册图片以加时间命名 System.IO.DirectoryInfo di = new System.IO.DirectoryInfo(dirPath); if (!di.Exists) { di.Create(); } string bImgName = appPath + fileName + "_big" + imgExtention; string mImgName = appPath + fileName + "_middle" + imgExtention; string sImgName = appPath + fileName + "_small" + imgExtention; imgFile.SaveAs(appPath + fileName + imgExtention);//临时保存原始图片 Bitmap bmp = new Bitmap(appPath + fileName + imgExtention); int width = bmp.Width; int height = bmp.Height; bmp.Dispose(); if (height <= width && width >= 600) { height = Convert.ToInt32(width > 600 ? (600f / width) * height : height); width = 600; } else if (width < height && height > 600) { width = Convert.ToInt32(height > 600 ? (600f / height) * width : height); height = 600; } // 将原始图压缩为大缩略图 using (StreamReader reader = new StreamReader(appPath + fileName + imgExtention)) { CY.Utility.Common.ImageUtility.ThumbAsJPG(reader.BaseStream, bImgName, width, height); } if (width > 200) { height = Convert.ToInt32(width > 200 ? (200f / width) * height : height); width = 200; } // 生成图片(好友上传图片最新通知中显示) using (StreamReader reader = new StreamReader(appPath + fileName + imgExtention)) { CY.Utility.Common.ImageUtility.ThumbAsJPG(reader.BaseStream, sImgName, width, height); } if (height <= width && width >= 100) { height = Convert.ToInt32(width > 100 ? (100f / width) * height : height); width = 100; } else if (width < height && height > 100) { width = Convert.ToInt32(height > 100 ? (100f / height) * width : height); height = 100; } // 将大图片压缩为中等缩略图 using (StreamReader reader = new StreamReader(appPath + fileName + imgExtention)) { CY.Utility.Common.ImageUtility.ThumbAsJPG(reader.BaseStream, mImgName, width, height); } try { File.Delete(appPath + fileName + imgExtention); } catch { ; } //将路径及图片信息保存到数据库 CY.UME.Core.Business.Picture pic = new Picture(); pic.AlbumId = album.Id; pic.BigPath = fileName + "_big" + imgExtention; pic.DateCreated = DateTime.Now; pic.MiddlePath = fileName + "_middle" + imgExtention; pic.Name = CY.Utility.Common.StringUtility.HTMLEncode(imgName.Substring(0, imgName.Length > 30 ? 30 : imgName.Length)); pic.SmallPath = fileName + "_small" + imgExtention; pic.Save(); //保存pictureextend CY.UME.Core.Business.PictureExtend pe = new PictureExtend(); pe.Id = pic.Id; pe.AccountId = account.Id; pe.ActivityId = "group"; pe.ActivityPicId = "0"; pe.Save(); context.Response.Write("1"); if (group.ViewPermission == 1) { IList<CY.UME.Core.Business.Friendship> fsList = account.GetFriendships(); foreach (CY.UME.Core.Business.Friendship fs in fsList) { List<CY.UME.Core.Business.Notice> noticeList = CY.UME.Core.Business.Notice.GetAllNoticeByAccountAndFriendAndType(account, fs.Friend, "grouppicture", false); foreach (CY.UME.Core.Business.Notice notice in noticeList) { if (notice != null && DateTime.Compare(DateTime.Now, notice.DateCreated.AddMinutes(10)) <= 0) { string strPicTemp = notice.InstanceId.Split(',')[0]; long picIdTemp = 0; if (long.TryParse(strPicTemp, out picIdTemp)) { CY.UME.Core.Business.Picture picTemp = CY.UME.Core.Business.Picture.Load(picIdTemp); if (picTemp != null && picTemp.AlbumId == pic.AlbumId) { notice.InstanceId += "," + pic.Id; notice.Save(); break; } } } CY.UME.Core.Business.Notice n = new CY.UME.Core.Business.Notice(); n.AccountId = fs.FriendId; n.AuthorId = fs.AccountId; n.Content = "上传了新照片"; n.DateCreated = DateTime.Now; n.InstanceId = pic.Id.ToString(); n.IsReaded = false; n.Type = "grouppicture"; n.Save(); } } } } }
public void ProcessRequest(HttpContext context) { context.Response.ContentType = "application/json"; long spaceId; // 空间用户的标识 long referedId; // 回复留言的标识 long InstanceId; string content; CY.UME.Core.Business.Account currentAccount; // 留言的用户 CY.UME.Core.Business.Account spaceAccount; // 所在个人主页的用户 CY.UME.Core.Business.PictureComment comment = new CY.UME.Core.Business.PictureComment(); CY.UME.Core.Business.PictureComment referedComment = new CY.UME.Core.Business.PictureComment(); // 所回复的留言 string mark=String.Empty; if ( !CY.Utility.Common.ParseUtility.TryParseInt64(context.Request.Form["referedId"], out referedId) || !CY.Utility.Common.ParseUtility.TryParseInt64(context.Request.Form["InstanceId"], out InstanceId)) { context.Response.Write("{success:false,msg:'参数错误'}"); return; } if (context.Request.Form["mark"] != null) { mark = context.Request.Form["mark"].ToString(); } if (context.Request.Form["spaceId"] == null || !long.TryParse(context.Request.Form["spaceId"].ToString(),out spaceId)) { spaceId = 0; } CY.UME.Core.Business.Picture picture = CY.UME.Core.Business.Picture.Load(InstanceId); if (picture == null) { context.Response.Write("{success:false,msg:'图片不存在或已被删除'}"); return; } CY.UME.Core.Business.Album album = CY.UME.Core.Business.Album.Load(picture.AlbumId); if (album == null) { context.Response.Write("{success:false,msg:'图片所在相册不存在或已被删除'}"); return; } currentAccount = CY.UME.Core.Global.GetCurrentAccount(); if (currentAccount == null) { context.Response.Write("{success:false,msg:'登录超时,请重新登录'}"); return; } if (mark == "group") { CY.UME.Core.Business.AlbumExtend albumExtend = CY.UME.Core.Business.AlbumExtend.Load(album.Id); CY.UME.Core.Business.Group group; int groupId = 0; if (!int.TryParse(albumExtend.InstanceId, out groupId)) { context.Response.Write("{success:false,msg:'图片所在群组不存在或已被删除'}"); return; } group = CY.UME.Core.Business.Group.Load(groupId); if (group == null) { context.Response.Write("{success:false,msg:'图片所在群组不存在或已被删除'}"); return; } if (group.AddPictureReplyPermission == 1 && !group.CheckIsGroupMember(currentAccount)) { context.Response.Write("{success:false,msg:'您无权评论该图片'}"); return; } CY.UME.Core.Business.PictureExtend pe = CY.UME.Core.Business.PictureExtend.Load(picture.Id); if (pe == null) { spaceId = pe.AccountId; } spaceId = pe.AccountId; } else { spaceId = album.AccountId; } // 所在个人主页的用户 if (spaceId == 0) { spaceId = currentAccount.Id; spaceAccount = currentAccount; } else { spaceAccount = CY.UME.Core.Business.Account.Load(spaceId); if (spaceAccount == null) { context.Response.Write("{success:false,msg:'用户不存在'}"); return; } } // 所回复的留言 if (referedId > 0) { referedComment = CY.UME.Core.Business.PictureComment.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; } #region Leave Msg,Notice // 将留言或者回复信息发送给空间主人 comment.AccountId = spaceAccount.Id; comment.Content = CY.Utility.Common.StringUtility.HTMLEncode(content); comment.ReferedId = referedId; comment.AuthorId = currentAccount.Id; comment.DateCreated = DateTime.Now; comment.InstanceId = InstanceId; 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 = InstanceId.ToString(); notice.Type = "picreply"; if (referedComment.Id > 0) { notice.AccountId = referedComment.AuthorId; if (referedComment.AuthorId == spaceAccount.Id) //回复空间主人 { notice.Content = "评论了您的照片"; } else // 在别人的日志处回复了另外一个人 { notice.Content = "回复了您的照片评论"; } } else { notice.AccountId = spaceAccount.Id; notice.Content = "评论了您的照片"; } 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; if (mark == "group") { notice.Type = "grouppicreply"; } else if (mark == "active") { notice.Type = "activepicreply"; } else { notice.Type = "picreply"; } notice.AccountId = referedComment.AuthorId; notice.Content = currentAccount.Name + "回复了您的照片评论"; notice.InstanceId = InstanceId.ToString(); notice.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(",cid:'"); sb.Append(currentAccount.Id); sb.Append("',d:'" + comment.DateCreated.ToString("yy-MM-dd HH:mm")+ "'}"); context.Response.Write(sb.ToString()); }