/// <summary> /// 获取评论数 /// </summary> /// <param name="userid"></param> /// <param name="start"></param> /// <param name="end"></param> /// <returns></returns> public int GetCommentCount(int userid, DateTime?start, DateTime?end) { string key = Com.GetCacheKey("commentbll.getcommentcount", userid.ToString(), ConvertHelper.GetString(start), ConvertHelper.GetString(end)); return(Cache(key, () => { var _commentDal = new CommentDal(); var count = 0; _commentDal.PrepareIQueryable((query) => { if (userid > 0) { query = query.Where(x => x.UserID == userid); } if (start != null) { query = query.Where(x => x.UpdateTime >= start.Value); } if (end != null) { query = query.Where(x => x.UpdateTime < end.Value); } count = query.Count(); return true; }); return count; })); }
//Action result for posting new comment public ActionResult post_comment() { //make comment Comment c = new Comment() { ThreadID = Int32.Parse(Request.Form["t_id"].ToString()), Author = ((SuperUser)Session["user"]).Username, Body = Request.Form["body_cmnt"].ToString(), time = DateTime.Now }; //post comment on sql CommentDal cdal = new CommentDal(); cdal.Comments.Add(c); cdal.SaveChanges(); //order the comment list List <Comment> f = cdal.Comments.ToList <Comment>(); f.OrderBy(x => x.time.TimeOfDay).ToList(); Comment_list = new ArrayList(f); //set the bag again ViewBag.Comments = Comment_list; //resend the view with the model return(View("ThreadPage", current_thread)); }
public UserManager(UserDTO user) { currentUser = user; userDal = new UserDal(user.Email); topicDal = new TopicDal(user.Email); commentDal = new CommentDal(user.Email); }
//Action result for deleting a thread public ActionResult DeleteThread() { ThreadDal td = new ThreadDal(); CommentDal cd = new CommentDal(); Thread t1, t2; string id = Request.Params .Cast <string>() .Where(p => p.StartsWith("button")) .Select(p => p.Substring("button".Length)) .First(); int i = Int32.Parse(id); t1 = (Thread)Thread_list[i]; t2 = (from x in td.Threads where t1.ID == x.ID select x).FirstOrDefault(); td.Threads.Remove(t2); td.SaveChanges(); List <Comment> comments = (from x in cd.Comments where x.ThreadID == t1.ID select x).ToList(); if (comments != null) { foreach (Comment comment in comments) { cd.Comments.Remove(comment); } cd.SaveChanges(); message = "Thread successfully deleted"; } return(RedirectToAction("Threads")); }
//Ctor public ThreadController() { CommentDal cdal = new CommentDal(); List <Comment> c = cdal.Comments.ToList <Comment>(); c.OrderBy(x => x.time.TimeOfDay).ToList(); c.Reverse(); Comment_list = new ArrayList(c); }
/// <summary> /// 删除评论 /// </summary> /// <param name="id"></param> /// <param name="userid"></param> /// <returns></returns> public string DeleteComment(string id, string userid) { var _commentDal = new CommentDal(); var model = _commentDal.GetFirst(x => x.UID == id && x.UserID == userid); if (model == null) { return("评论不存在"); } return(_commentDal.Delete(model) > 0 ? SUCCESS : "删除失败"); }
/// <summary> /// 获取多个评论对象 /// </summary> /// <param name="idlist"></param> /// <returns></returns> public List <CommentModel> GetCommentsByIDS(params string[] idlist) { if (!ValidateHelper.IsPlumpList(idlist)) { return(null); } var _commentDal = new CommentDal(); return(_commentDal.GetList(x => idlist.Contains(x.UID))); }
/// <summary> /// 获取评论分页 /// </summary> /// <param name="threadID"></param> /// <param name="page"></param> /// <param name="pagesize"></param> /// <returns></returns> public PagerData <CommentModel> GetComments(string threadID, int page, int pagesize) { if (!ValidateHelper.IsPlumpString(threadID)) { return(null); } string key = Com.GetCacheKey("commentbll.getcomments", threadID, page.ToString(), pagesize.ToString()); return(Cache(key, () => { var data = new PagerData <CommentModel>(); int[] range = PagerHelper.GetQueryRange(page, pagesize); var _commentDal = new CommentDal(); _commentDal.PrepareIQueryable((query) => { query = query.Where(x => x.ThreadID == threadID); data.ItemCount = query.Count(); data.DataList = query.OrderByDescending(x => x.CommentID) .Skip(range[0]).Take(range[1]).ToList(); return true; }); if (ValidateHelper.IsPlumpList(data.DataList)) { var useridlist = data.DataList.Select(x => x.UserID).Distinct().Where(x => x > 0).ToArray(); if (ValidateHelper.IsPlumpList(useridlist)) { var userbll = AppContext.GetObject <IUserService>(); var userlist = userbll.GetUserByIDS(useridlist); if (ValidateHelper.IsPlumpList(userlist)) { data.DataList.ForEach(x => { x.UserModel = userlist.Where(m => m.UserID == x.UserID).FirstOrDefault(); }); } } var parentidlist = data.DataList.Select(x => x.ParentCommentID).Distinct().Where(x => x > 0).ToArray(); if (ValidateHelper.IsPlumpList(parentidlist)) { var commentslist = GetCommentsByIDS(parentidlist); if (ValidateHelper.IsPlumpList(commentslist)) { data.DataList.ForEach(x => { x.ParentComment = commentslist.Where(m => m.CommentID == x.ParentCommentID).FirstOrDefault(); }); } } } return data; })); }
public void getCommentTest() { RecipesController recipes = new RecipesController(); Comment comment = new Comment(); comment.date = DateTime.Now; comment.id = Hashing.HashPassword(new Random().Next(12023, 132023).ToString()); CommentDal commentDal = new CommentDal(); Assert.IsNotNull(commentDal); }
/// <summary> /// 添加评论 /// </summary> /// <param name="model"></param> /// <returns></returns> public string AddComment(CommentModel model) { string check = CheckModel(model); if (ValidateHelper.IsPlumpString(check)) { return(check); } var _commentDal = new CommentDal(); var count = _commentDal.Add(model); return(count > 0 ? SUCCESS : "评论失败"); }
public void TestFollowUser() { //Arrange var controller = new CommunicationControllerTest(); User cur1 = new User { UserName = "******", Password = "******" }; User cur2 = new User { UserName = "******", Password = "******" }; UserDal usrd = new UserDal(); User cur1_Obj = usrd.Users.SingleOrDefault(b => b.UserName == cur1.UserName); User cur2_Obj = usrd.Users.SingleOrDefault(b => b.UserName == cur2.UserName); CommentDal cmtd = new CommentDal(); Comment testComment = new Comment() { commentContent = "Testing Comment 1122334455", userId = cur2_Obj.id, threadId = 1 }; cmtd.Comments.Add(testComment); cmtd.SaveChanges(); Comment testId = cmtd.Comments.SingleOrDefault(b => b.commentContent == testComment.commentContent); //Act controller.follow(testId.commentId, cur1_Obj); //Assert FollowDal fdal = new FollowDal(); List <Follow> f = (from x in fdal.Follows where x.follower == cur1_Obj.id && x.followOn == cur2_Obj.id select x).ToList(); Assert.IsTrue(f.Any()); //Clean Up cmtd.Comments.Remove(testId); cmtd.SaveChanges(); fdal.Follows.Remove(f[0]); fdal.SaveChanges(); }
/// <summary> /// 获取多个评论对象 /// </summary> /// <param name="idlist"></param> /// <returns></returns> public List <CommentModel> GetCommentsByIDS(params int[] idlist) { if (!ValidateHelper.IsPlumpList(idlist)) { return(null); } string key = Com.GetCacheKey("commentbll.GetCommentsByIDS", string.Join(",", idlist)); return(Cache(key, () => { var _commentDal = new CommentDal(); return _commentDal.GetList(x => idlist.Contains(x.CommentID)); })); }
/// <summary> /// 删除评论 /// </summary> /// <param name="id"></param> /// <param name="userid"></param> /// <returns></returns> public string DeleteComment(int id, int userid) { if (id <= 0 || userid <= 0) { return("参数错误"); } var _commentDal = new CommentDal(); var model = _commentDal.GetFirst(x => x.CommentID == id && x.UserID == userid); if (model == null) { return("评论不存在"); } return(_commentDal.Delete(model) > 0 ? SUCCESS : "删除失败"); }
public JsonResult getComment() { Comment comment = new Comment(); comment.email = Request.Form["email"]; comment.message = Request.Form["message"]; comment.date = DateTime.Now; comment.idReceips = Request.Form["recipesId"]; comment.id = Hashing.HashPassword(new Random().Next(12023, 132023).ToString()); CommentDal commentDal = new CommentDal(); commentDal.Comments.Add(comment); commentDal.SaveChanges(); return(Json(new { statut = true }, JsonRequestBehavior.AllowGet)); }
public RecipeComCVM(string idRecipes) { RecipesDal recipesDal = new RecipesDal(); CommentDal commentDal = new CommentDal(); List <Recipes> food = (from x in recipesDal.Recipes where x.Id.Equals(idRecipes) select x).ToList(); if (food.Count > 0) { recipes = food[0]; } else { recipes = null; } comments = (from x in commentDal.Comments where x.idReceips.Equals(idRecipes) orderby x.date select x).ToList(); }
/// <summary> /// 获取评论分页 /// </summary> /// <param name="threadID"></param> /// <param name="page"></param> /// <param name="pagesize"></param> /// <returns></returns> public PagerData <CommentModel> GetComments(string threadID, int page, int pagesize) { if (!ValidateHelper.IsPlumpString(threadID)) { return(null); } var data = new PagerData <CommentModel>(); var _commentDal = new CommentDal(); _commentDal.PrepareIQueryable((query) => { query = query.Where(x => x.ThreadID == threadID); data.ItemCount = query.Count(); data.DataList = query.OrderByDescending(x => x.CreateTime).QueryPage(page, pagesize).ToList(); return(true); }); return(data); }
public ActionResult unFollow(Int32 i) { ThreadDal tdal = new ThreadDal(); CommentDal cdal = new CommentDal(); FollowDal fdal = new FollowDal(); List <Follow> follows = new List <Follow>(); List <Comment> comments = new List <Comment>(); List <Thread> threads = new List <Thread>(); User ur = new User((User)TempData["urid"]); try { comments = (from x in cdal.Comments where x.commentId == i select x).ToList <Comment>(); int on = comments[0].userId; int tid = comments[0].threadId; int fwr = ur.id; threads = (from x in tdal.Threads where x.ThreadId == tid select x).ToList <Thread>(); follows = (from y in fdal.Follows where y.followOn == @on && y.follower == fwr select y).ToList <Follow>(); fdal.Follows.Remove(follows[0]); fdal.SaveChanges(); } catch { } Thread t = new Thread(threads[0]); return(RedirectToAction("ContentPage", "MainPage", t)); }
public ActionResult DeleteComment() { if (Session["Log"] == null) { ViewBag.Error = "not logged"; return(View("~/Views/Home/NotLogged.cshtml")); } CommentDal ud = new CommentDal(); Comment test = new Comment() { id = Request.Form["id"].ToString() }; var customer = ud.Comments.Single(o => o.id == test.id); ud.Comments.Remove(customer); ud.SaveChanges(); return(null); }
//Action result for single thread with all it's comments public ActionResult ThreadPage() { CommentDal cdal = new CommentDal(); List <Comment> f = cdal.Comments.ToList <Comment>(); f.OrderBy(x => x.time.TimeOfDay).ToList(); Comment_list = new ArrayList(f); ViewBag.Comments = Comment_list; string id = Request.Params .Cast <string>() .Where(p => p.StartsWith("button")) .Select(p => p.Substring("button".Length)) .First(); int i = Int32.Parse(id); current_thread = (Thread)Thread_list[i]; current_thread.Body.Replace("\r\n", "<br />"); return(View(current_thread)); }
/// <summary> /// 获取评论数 /// </summary> /// <param name="userid"></param> /// <param name="start"></param> /// <param name="end"></param> /// <returns></returns> public int GetCommentCount(string userid, DateTime?start, DateTime?end) { var _commentDal = new CommentDal(); var count = 0; _commentDal.PrepareIQueryable((query) => { if (ValidateHelper.IsPlumpString(userid)) { query = query.Where(x => x.UserID == userid); } if (start != null) { query = query.Where(x => x.UpdateTime >= start.Value); } if (end != null) { query = query.Where(x => x.UpdateTime < end.Value); } count = query.Count(); return(true); }); return(count); }
public CommentModel GetCommentByID(string id) { var _commentDal = new CommentDal(); return(_commentDal.GetFirst(x => x.UID == id)); }
public void TestNewComment() { //Arragne var controller = new MainPageControllerTest(); string content = "Test Content TESTING!!!!"; Syear inst = new Syear { SyearId = 1 }; User cur = new User { UserName = "******", Password = "******" }; Thread test_Thread = new Thread { ThreadName = testingThreadHeader, SyearId = 1, ThreadType = "[Question]", OwnerId = 1 }; ThreadDal tDal = new ThreadDal(); tDal.Threads.Add(test_Thread); // Add test thread tDal.SaveChanges(); Thread currenthread = tDal.Threads.SingleOrDefault(b => b.ThreadName == testingThreadHeader); Content testContent = new Content() { threadContent = content, threadId = currenthread.ThreadId }; ContentDal cDal = new ContentDal(); cDal.Contents.Add(testContent); cDal.SaveChanges(); //Act controller.addComment(testContent, cur, "TestComment"); //Assert CommentDal comDal = new CommentDal(); List <Comment> com = (from x in comDal.Comments where x.threadId == currenthread.ThreadId select x).ToList(); Comment ans = com.Find(b => b.commentContent == "TestComment"); Assert.IsNotNull(ans); //CleanUp tDal.Threads.Remove(currenthread); tDal.SaveChanges(); cDal.Contents.Remove(testContent); cDal.SaveChanges(); comDal.Comments.Remove(ans); comDal.SaveChanges(); }
/// <summary> /// 根据商品id查询该商品的评价 /// </summary> /// <param name="goodsid">商品id</param> /// <returns></returns> public static List <CommentTable> SelectGoodsComment(int goodsid) { return(CommentDal.SelectGoodsComment(goodsid)); }
public static void Main(string[] args) { Console.OutputEncoding = System.Text.Encoding.Default; //string connStr = ConfigurationManager.ConnectionStrings["ManagerNews"].ConnectionString; string connectionString = "Data Source=localhost;Initial Catalog=ManagerNews;Integrated Security=True"; topicDal = new TopicDal(connectionString); userDal = new UserDal(connectionString); commentDal = new CommentDal(connectionString); uint isLogIn = LogIn(); while (isLogIn != 0) { //Console.Clear(); Console.WriteLine("\n\n What do you want to DO?"); Console.WriteLine("\ntype 'l' to get List of entities"); Console.WriteLine("type 's' to Sort entity"); Console.WriteLine("type 'f' to Find entity"); if (isLogIn == 2) { Console.WriteLine("type 'a' to Add entity"); Console.WriteLine("type 'r' to Remove entity"); } //... Console.WriteLine("type 'o' to logOut"); Console.WriteLine("type 'q' to Quit"); try { char c = char.Parse(Console.ReadLine()); switch (c) { case 'l': //show list of entities { Console.WriteLine("\nList of all entity:"); PrintAll(); } break; case 's': // { Console.WriteLine("\nSorted by Title:"); PrintSorted(); } break; case 'a': //create new entity { Console.WriteLine("Add:"); AddUser(); } break; case 'r': //remove entity { Console.WriteLine("If you are the Owner or Administrator you can delete the user.\nEnter ID:"); if (isLogIn == 2) { int id = int.Parse(Console.ReadLine()); topicDal.Delete(id); } else { throw new Exception("Not permission"); } } break; case 'f': { Console.WriteLine("Please, enter a word or letters or a price: "); // find by Title string ttl = Console.ReadLine().ToString(); Find(ttl); } break; case 'o': { isLogIn = LogIn(); } break; case 'q': return; } } catch (Exception e) { Console.WriteLine(e.Message); } } }
/// <summary> /// 查询所有评论 /// </summary> /// <returns></returns> public static List <CommentTable> SelectAllComment() { return(CommentDal.SelectAllComment()); }
/// <summary> /// 评论举报 /// </summary> /// <param name="commentid">评论id</param> /// <returns></returns> public static bool AddReport(int commentid) { return(CommentDal.AddReport(commentid) == 1); }
/// <summary> /// 根据tid查询商品评论 /// </summary> /// <param name="tid"></param> /// <returns></returns> public static List <CommentTable> SelectByTidComment(int tid) { return(CommentDal.SelectByTidComment(tid)); }
/// <summary> /// 删除评价 /// </summary> /// <param name="commentid">评价id</param> /// <returns></returns> public static bool DeleteUserComment(int commentid) { return(CommentDal.DeleteUserComment(commentid) == 1); }
public ActionResult addLike(String i) { TempData["canLike"] = true; Thread trd = (Thread)TempData["CurrentThread"]; int id = (int)TempData["CurrentId" + i]; Comment cmt = (Comment)TempData["CurrentCmt" + i]; LikeDal ldal = new LikeDal(); List <Like> lk = new List <Like>(); try { lk = (from x in ldal.Likes where x.threadId == trd.ThreadId && x.commentId == cmt.commentId && x.usrId == id select x).ToList <Like>(); } catch { } if (lk.Any()) { TempData["canLike"] = 0; ldal.Likes.Remove(lk[0]); ldal.SaveChanges(); UserDal dal = new UserDal(); List <User> Users = new List <User>(); try { Users = (from x in dal.Users where x.id == id select x).ToList <User>(); } catch { } int powRate = (Users[0].Likes / 10000) + 1; CommentDal cdal = new CommentDal(); List <Comment> com = new List <Comment>(); try { com = (from x in cdal.Comments where x.threadId == trd.ThreadId && x.commentId == cmt.commentId select x).ToList <Comment>(); } catch { } for (int idx = 0; idx < powRate; idx++) { com[0].rank--; refreshLikes(cmt.userId, false); } cdal.SaveChanges(); } else { if (!canLike(id)) { TempData["canLike"] = -1; } else { TempData["canLike"] = 0; Like tmplk = new Like() { commentId = cmt.commentId, threadId = trd.ThreadId, usrId = id }; ldal.Likes.Add(tmplk); ldal.SaveChanges(); UserDal dal = new UserDal(); CommentDal cdal = new CommentDal(); List <User> Users = new List <User>(); List <Comment> com = new List <Comment>(); try { Users = (from x in dal.Users where x.id == id select x).ToList <User>(); } catch { } int powRate = (Users[0].Likes / 10000) + 1; try { (from x in cdal.Comments where x.threadId == trd.ThreadId && x.commentId == cmt.commentId select x).ToList <Comment>(); } catch { } for (int idx = 0; idx < powRate; idx++) { com[0].rank++; refreshLikes(cmt.userId, true); } cdal.SaveChanges(); } } return(RedirectToAction("ContentPage", "MainPage", trd)); }
/// <summary> /// 评论是否置顶操作 /// </summary> /// <param name="commentid">评论id</param> /// <param name="istop">是否置顶</param> /// <returns></returns> public static bool UpdateIsTop(int commentid, string istop) { return(CommentDal.UpdateIsTop(commentid, istop) == 1); }