public static ResponceModel Change(string username, int id, string content, string pic) { if (content != "") { MsgUni msg = new MsgUni(id); if (msg.TryQuery()) { if (msg.mark == 2) { return(new ResponceModel(403, "该留言已删除")); } msg.content = content; if (pic != null) { msg.pic = ToolUtil.HexToByte(pic); } msg.Update("body"); msg.SavePic(); return(new ResponceModel(200, "修改留言成功", msg)); } else { return(new ResponceModel(403, "该留言不存在")); } } else { return(new ResponceModel(403, "留言内容为空")); } }
public static ResponceModel AddComment(string username, int id, string content) { if (content == "") { return(new ResponceModel(403, "评论内容为空")); } else { MsgUni msg = new MsgUni(id); if (msg.TryQuery()) { var comments = msg.comments.ToList(); comments.Add(new MsgComment(++msg.commentlastid, username, DateTime.Now.ToString(), content)); msg.comments = comments.ToArray(); msg.updatetime = DateTime.Now.ToString(); msg.Update("comments"); //msg.Update("updatetime"); return(new ResponceModel(200, "添加评论成功", msg)); } else { return(new ResponceModel(403, "该留言不存在")); } } }
public static ResponceModel DeleteCommnet(string username, int id, int subid) { MsgUni msg = new MsgUni(id); if (msg.TryQuery()) { UserInfoSql userInfo = new UserInfoSql(username); userInfo.TryQuery(); // Mark: 找到该评论,并删除。 var comments = from item in msg.comments where item.id == subid select item; if (comments == null || comments.Count() == 0) { return(new ResponceModel(403, "该评论不存在")); } else { // Mark: 获取该评论 var comment = comments.First(); bool isdelete = false; string remsg = ""; if (comment.username == username) { isdelete = true; remsg = "删除评论成功"; //return new ResponceModel(200, "删除留言成功"); } // 糟糕,该用户具有管理员管理员权限 else if (userInfo.permission_msgboard > 0) { // TODO 通知原用户已被删除。 UserInfoSql userInfoowner = new UserInfoSql(comment.username); userInfoowner.TryQuery(); // 这个要看谁是爸爸。评论发布者和尝试删除者进行PK。 if (userInfoowner.permission_msgboard < userInfo.permission_msgboard) { isdelete = true; remsg = "删除评论成功"; //return new ResponceModel(200,"") } else { isdelete = false; remsg = "用户权限不够"; } } if (isdelete) { var newcomments = msg.comments.Except(comments); msg.comments = newcomments.ToArray(); msg.updatetime = DateTime.Now.ToString(); msg.Update("comments"); return(new ResponceModel(200, "删除评论成功", msg)); } else { return(new ResponceModel(403, remsg)); } } } else { return(new ResponceModel(403, "该留言不存在")); } }
public static ResponceModel Delete(string username, int id) { MsgUni msg = new MsgUni(id); if (msg.TryQuery()) { UserInfoSql userInfo = new UserInfoSql(username); userInfo.TryQuery(); bool isdelete = false; string remsg = ""; if (msg.username == username) { isdelete = true; remsg = "删除留言成功"; //return new ResponceModel(200, "删除留言成功"); } // 糟糕,该用户具有管理员管理员权限 else if (userInfo.permission_msgboard > 0) { // TODO 通知原用户已被删除。 UserInfoSql userInfoowner = new UserInfoSql(msg.username); userInfoowner.TryQuery(); // 这个要看谁是爸爸。 if (userInfoowner.permission_msgboard < userInfo.permission_msgboard) { isdelete = true; remsg = "删除留言成功"; //return new ResponceModel(200,"") } else { isdelete = false; remsg = "用户权限不够"; } } // SOLVED BUG 这里曾导致了普通用户没有反馈的问题。 else { isdelete = false; remsg = "用户权限不够"; } if (isdelete) { if (msg.mark == 0) { msg.mark = 2; // Mark: 这同时也会更新时间。 //SOLVED BUG 更新时间戳标记。 msg.updatetime = DateTime.Now.ToString(); msg.Update("mark"); } return(new ResponceModel(200, remsg)); } else { return(new ResponceModel(403, remsg)); } } else { return(new ResponceModel(403, "该留言不存在")); } }