public List <BasicCommentThread> GetSubCommentInThreadById(int CommentId, string currentUserName) { int CurrenUser = 0; if (currentUserName != "") { using (var db = new UserDAL()) { CurrenUser = db.GetUserByUserNameOrEmail(currentUserName).UserID; } } List <BasicCommentThread> list = new List <BasicCommentThread>(); using (var db = new Ws_DataContext()) { try { var listComment = db.SubCommentThread .Where(x => x.Status == true && x.CommentThreadId == CommentId) .Select(x => new { x.UserId, x.Ws_User.UserName, x.Ws_User.User_Information.ProfileImage, x.SubCommentThreadId, x.Content, x.CommentDate }) .OrderByDescending(x => x.CommentDate).ToList(); foreach (var item in listComment) { BasicCommentThread bs = new BasicCommentThread(); bs.UserCommentedId = item.UserId; bs.UserCommentedName = item.UserName; bs.UserImageProfile = item.ProfileImage; bs.CommentId = item.SubCommentThreadId; bs.Content = item.Content; if (CurrenUser == item.UserId) { bs.isDeleted = true; } else { bs.isDeleted = false; } if (DateTime.Now.Subtract(item.CommentDate).TotalHours <= 24 && DateTime.Now.Subtract(item.CommentDate).TotalHours >= 1) { bs.CommentedTime = Math.Round(DateTime.Now.Subtract(item.CommentDate).TotalHours, 0) + " Tiếng cách đây"; } else if (DateTime.Now.Subtract(item.CommentDate).TotalHours > 24) { bs.CommentedTime = item.CommentDate.ToString("H:mm:ss dd/MM/yy"); } else if (DateTime.Now.Subtract(item.CommentDate).Minutes == 0) { bs.CommentedTime = "Vừa xong"; } else { bs.CommentedTime = DateTime.Now.Subtract(item.CommentDate).Minutes + " Phút cách đây"; } list.Add(bs); } } catch (Exception) { return(null); } } return(list); }
public List <BasicCommentThread> GetAllSubCommentInEvent() { List <BasicCommentThread> list = new List <BasicCommentThread>(); using (var db = new Ws_DataContext()) { try { var listComment = db.SubCommentEvent .Where(x => x.Status == true) .Select(x => new { x.UserId, x.Ws_User.UserName, x.Ws_User.User_Information.ProfileImage, x.CommentEventId, x.Content, x.CommentDate }) .OrderByDescending(x => x.CommentDate).ToList(); foreach (var item in listComment) { BasicCommentThread bs = new BasicCommentThread(); bs.UserCommentedId = item.UserId; bs.UserCommentedName = item.UserName; bs.UserImageProfile = item.ProfileImage; bs.CommentId = item.CommentEventId; bs.Content = item.Content; if (DateTime.Now.Subtract(item.CommentDate).TotalHours <= 24 && DateTime.Now.Subtract(item.CommentDate).TotalHours >= 1) { bs.CommentedTime = Math.Round(DateTime.Now.Subtract(item.CommentDate).TotalHours, 0) + " Tiếng cách đây"; } else if (DateTime.Now.Subtract(item.CommentDate).TotalHours > 24) { bs.CommentedTime = item.CommentDate.ToString("H:mm:ss dd/MM/yy"); } else if (DateTime.Now.Subtract(item.CommentDate).Minutes == 0) { bs.CommentedTime = "Vừa xong"; } else { bs.CommentedTime = DateTime.Now.Subtract(item.CommentDate).Minutes + " Phút cách đây"; } list.Add(bs); } } catch (Exception) { return(null); } } return(list); }