public CommentsViewModel GetPagedCommentsByPostId(int postId, string author, SortParametersDto sortParameters) { var store = new UserStore <ApplicationUser>(new ApplicationDbContext()); var userManager = new UserManager <ApplicationUser>(store); CommentsViewModel commentsViewModel = new CommentsViewModel { Comments = new List <CommentViewModel>() }; var comments = _db.Comments.Where(comment => comment.PostID.Equals(postId)).ToList(); comments.ForEach(comment => { ApplicationUser commentAuthor = userManager.FindByIdAsync(comment.Author).Result; CommentViewModel comm = new CommentViewModel { Profile = _db.Profiles.FirstOrDefault(pr => pr.ApplicationUser.Equals(comment.Author)) }; if (commentAuthor != null) { comment.Author = commentAuthor.UserName; } comm.Comment = comment; commentsViewModel.Comments.Add(comm); }); commentsViewModel.Comments = commentsViewModel.Comments.Skip((sortParameters.CurrentPage - 1) * sortParameters.PageSize).Take(sortParameters.PageSize).ToList(); commentsViewModel.PageInfo = new PageInfo { PageNumber = sortParameters.CurrentPage, PageSize = sortParameters.PageSize, TotalItems = comments.Count }; return(commentsViewModel); }
// GET: Patients public ActionResult Index() { var viewModel = new PostsViewModel(); var patientId = User.Identity.GetUserId(); var userType = db.Users.FirstOrDefault(x => x.Id == patientId).UserType; ViewBag.PatientId = patientId; ViewBag.UserType = userType; viewModel.Categories = db.Categories.Include(p => p.Posts).Where(x => x.Posts.Any()).ToList(); viewModel.CommentsViewModel = new List <CommentsViewModel>(); foreach (var category in viewModel.Categories) { foreach (var post in category.Posts) { var postComments = db.Comments.Where(x => x.PostId == post.Id).ToList(); foreach (var comment in postComments) { var commentViewModel = new CommentsViewModel() { Comment = comment, OwnerName = db.Users.FirstOrDefault(x => x.Id == comment.DoctorId).UserName, }; viewModel.CommentsViewModel.Add(commentViewModel); } } } return(View(viewModel)); }
public ActionResult ViewComments(CommentsViewModel model) { if (ModelState.IsValid) { if (string.IsNullOrEmpty(User.Identity.GetUserId())) { ModelState.AddModelError("User", "User not logged in"); return(View(GetCommentsViewModelFor(model.PostId))); } Comment comment = new Comment() { Text = model.NewCommentText, PostId = model.PostId, StudentId = model.CurrentStudentId, TimeAnswered = DateTime.Now }; StudentComment studentComment = new StudentComment() { CommentId = comment.Id, StudentId = comment.StudentId, Voted = false }; Post post = db.Posts.Include(p => p.Comments).FirstOrDefault(p => p.Id == model.PostId); post.Comments.Add(comment); db.StudentComments.Add(studentComment); db.SaveChanges(); return(RedirectToAction("ViewComments", new { postId = model.PostId })); } return(View(GetCommentsViewModelFor(model.PostId))); }
// GET: Comments public ActionResult Index(int?postId) { if (postId == null) { return(View("Error")); } TempData["postId"] = postId; List <Comment> comments = new List <Comment>(); comments = db.Comments.Include(c => c.Op).Include(c => c.Post).Where(c => c.PostId == postId).ToList(); CommentsViewModel commentsViewModel = new CommentsViewModel { UserImage = User.Identity.IsAuthenticated ? db.Users.Find(User.Identity.GetUserId()).Image_url : null, IsAdmin = User.IsInRole(Const.ADMIN), IsMod = User.IsInRole(Const.MODERATOR), IsUser = User.Identity.IsAuthenticated, PostId = postId, Comments = comments, Post = db.Posts.Find(postId) }; //TODO: ask how do I deal with partials and ViewModels data aka without using ViewBag ViewBag.IsAdmin = User.IsInRole(Const.ADMIN); ViewBag.IsMod = User.IsInRole(Const.MODERATOR); ViewBag.UserID = User.Identity.GetUserId(); return(View(commentsViewModel)); }
public ActionResult ViewComments(int postId) { CommentsViewModel model = GetCommentsViewModelFor(postId); model.Comments = model.Comments.OrderByDescending(s => (s.VotesUp - s.VotesDown)).ThenByDescending(s => s.TimeAnswered).ToList(); return(View(model)); }
protected override async Task LoadDetails(long id) { var rs = await _dataSource.GetSelectionDetails(id); if (rs == null) { return; } LayoutHelper.InvokeFromUiThread(async() => { Title = rs.Title.GetNormalString(); Description = rs.Description; foreach (var image in rs.Images) { _images.Add(image.Image); } foreach (var item in rs.Items) { _selections.Add(new SelectionDetailsNodeViewModel(item, _dataSource)); } await CommentsViewModel.Load(); }); }
public async Task <IActionResult> Comment(int id, [FromBody] Comment comment) { var moderationItem = _ctx.ModerationItems.FirstOrDefault(x => x.Id == id); if (moderationItem == null) { return(NoContent()); } var regex = new Regex(@"\B(?<tag>@[a-zA-Z0-9-_]+)"); comment.HtmlContent = regex.Matches(comment.Content) .Aggregate(comment.Content, (content, match) => { var tag = match.Groups["tag"].Value; return(content .Replace(tag, $"<a href=\"{tag}-user-link\">{tag}</a>")); }); moderationItem.Comments.Add(comment); await _ctx.SaveChangesAsync(); return(Ok(CommentsViewModel.Create(comment))); }
private static void ComposeObjects() { var api = new ClientApi(); var archiveVm = new ArchiveViewModel(); var commentsVm = new CommentsViewModel(); var newEmployeeVm = new EmployeeViewModel(); var employeesVm = new EmployeesViewModel(newEmployeeVm); var loginVm = new LoginViewModel(api); var forgetPasswodVm = new ForgetPasswordViewModel(); var myTasksVm = new MyTasksViewModel(); var newTaskVm = new NewTaskViewModel(); var profileVm = new ProfileViewModel(); var trackingTasksVm = new TrackingTasksViewModel(newTaskVm); var reportsVm = new ReportsViewModel(); var mainWindowVm = new MainWindowViewModel(archiveVm, commentsVm, employeesVm, loginVm, forgetPasswodVm, myTasksVm, profileVm, reportsVm, trackingTasksVm); Current.MainWindow = new MainWindow(mainWindowVm); }
protected override DriverResult Editor(CRMCommentsPart part, dynamic shapeHelper) { CommentsViewModel model = new CommentsViewModel(); var comments = this.commentPartRecordRepository.Table.Where(c => c.CRMCommentsPartRecord.Id == part.Record.Id).ToList(); var users = this.services.ContentManager.GetMany <IUser>(comments.Where(c => c.User != null).Select(c => c.User.Id), VersionOptions.Published, QueryHints.Empty); model.Id = part.Record.Id; model.CommentsCount = part.Record.CommentsCount; foreach (var record in comments) { model.Comments.Add(this.Convert(record, users)); } return(this.Combined( ContentShape("Parts_CRMComments_Edit", () => shapeHelper.EditorTemplate( TemplateName: "Parts/CRMComments", Model: model, Prefix: Prefix)), ContentShape("Parts_CRMComments", () => shapeHelper.Parts_CRMComments( Model: model, Prefix: Prefix)) )); }
public async Task <IActionResult> Comment(CommentsViewModel model) { model.userId = Guid.Parse(GetUser().Result.Id); await commentsService.CommentOnPost(model); return(Ok()); }
protected override async Task LoadDetails(long id) { var rs = await _dataSource.GetPlaceDetails(id); if (rs == null) { return; } LayoutHelper.InvokeFromUiThread(async() => { Title = rs.Title.GetNormalString(); Description = rs.Description.GetNormalString(); BodyText = rs.BodyText.GetNormalString(); Adress = rs.Address; Phone = rs.Phone; Timetable = rs.Timetable; IsClosed = rs.IsClosed; if (!string.IsNullOrEmpty(rs.SiteUrl)) { Source = new Uri(rs.SiteUrl); } foreach (var image in rs.Images) { _images.Add(image.Image); } Metro = rs.Subway; Location = rs.Coords; await CommentsViewModel.Load(); }); }
public PartialViewResult Comments(CommentsViewModel model) { model.CommentedBaseScoreCards = this.baseScoreCardRepository.Find(model.ToFilter()); model.CommentedValuationScoreCards = this.valuationScoreCardRepository.Find(model.ToFilter()); return(this.PartialView(model)); }
public ActionResult Index() { var comments = new List <CommentViewModel>(); foreach (var item in _comments) { comments.Add(new CommentViewModel { User = item.User, Text = item.Text, Data = item.Data.ToLongTimeString() }); } CommentsViewModel commentsViewModel = new CommentsViewModel { Comments = comments, NewComment = new CommentsViewModel.CommentInput { User = "******", Text = "Default" } }; return(View(commentsViewModel)); }
public PartialViewResult LoadCommentsForPost(long postId) { logginghelper.Log(LoggingLevels.Info, "Class: " + classname + " :: LoadCommentsForPost - Begin"); List <CommentsViewModel> _lstCommentsViewModel = new List <CommentsViewModel>(); try { List <Comment> _lstComments = dataaccess.GetCommentsByPostId(postId); if (_lstComments != null && _lstComments.Count > 0) { foreach (var comment in _lstComments) { CommentsViewModel objCommentViewModel = new CommentsViewModel(); objCommentViewModel.Comment = comment; if (comment.IsReply == true) { Reply reply = new Reply(); reply = dataaccess.GetReplyForComment(comment.Comment_Id); objCommentViewModel.Reply = reply; } _lstCommentsViewModel.Add(objCommentViewModel); } } ViewBag.PostId = postId; } catch (Exception ex) { logginghelper.Log(LoggingLevels.Error, "Class: " + classname + " :: LoadCommentsForPost " + ex); } logginghelper.Log(LoggingLevels.Info, "Class: " + classname + " :: LoadCommentsForPost - End"); return(PartialView(_lstCommentsViewModel)); }
public object AddComment([FromBody] CommentsViewModel webCommentsViewModel) { try { var id = webCommentsViewModel.UserId; Comment commentResponse = new Comment(); DateTimeOffset timestamp = DateTimeOffset.Now; commentResponse = _feedResponseRepository.AddComment(id, webCommentsViewModel.FeedId, webCommentsViewModel.Comments, timestamp); return(new SingleResponse <Comment> { Message = "Comment Added Successfully", DidError = false, ErrorMessage = string.Empty, Token = string.Empty, Model = commentResponse }); } catch (Exception ex) { return(new SingleResponse <Comment> { Message = ex.InnerException.ToString(), DidError = true, ErrorMessage = ex.Message, Token = string.Empty, Model = null }); } }
public ActionResult Index(CommentsViewModel model) { if (ModelState.IsValid) { var newComment = new CommentDTO { Author = model.NewCommentAuthor, Text = model.NewCommentText, Date = DateTime.Now }; _commentsSerice.AddComment(newComment); } else { var errors = new List <String>(); foreach (ModelState modelState in ViewData.ModelState.Values) { foreach (ModelError error in modelState.Errors) { errors.Add(error.ErrorMessage); } } ViewBag.Errors = errors; } var comments = _commentsSerice.GetComments(); var viewModel = new CommentsViewModel(); viewModel.Commets = comments; return(PartialView("_CommentsPartial", viewModel)); }
public async Task <IActionResult> RankComment([FromBody] CommentsViewModel commentsViewModel) { var originalUser = await _helpService.ExistUser(User); if (originalUser == null) { return(BadRequest()); } if (commentsViewModel.Id > 0 && commentsViewModel.Rank > 0) { var user = await _catalogService.GetUserByOriginalId(originalUser.Id); var amountRanks = await _catalogService.CheckRankUser(commentsViewModel.Id, user.Id); if (amountRanks > 0) { return(BadRequest()); } await _catalogService.AddRankForComment(commentsViewModel.Id, commentsViewModel.Rank, user.Id); return(Ok()); } return(BadRequest()); }
public ActionResult CommentsPartial(Guid id) { //Fix this :@ var db = ApplicationDbContext.Create(); var model = new CommentsViewModel() { Comment = new List <CommentPartialModel>() }; this.commentService.GetCommentsForArticle(id).ToList().ForEach(x => { string currentId = x.AccountId.ToString(); var user = db.Users.Where(y => y.Id == currentId).Select(y => y.UserName).FirstOrDefault(); model.Comment.Add(new CommentPartialModel() { Author = user, AuthorId = x.AccountId, Content = x.Description, Date = x.Date }); }); return(this.PartialView("CommentsPartial", model)); }
public async Task <List <CommentsViewModel> > GetCommentsAsync(int saleId) { var comments = await _catalogService.GetCommentsAsync(saleId); List <CommentsViewModel> commentsMap = new List <CommentsViewModel>(); var childs = comments.Where(x => x.Rank > 0 && x.FkParrentComment != null).OrderBy(c => c.Rank).ToList(); foreach (var childComment in childs) { var index = comments.FindIndex(a => a.Id == childComment.FkParrentComment); var indexChildren = comments.FindIndex(b => b.Id == childComment.Id); var changeParrentPosition = comments[index]; comments.RemoveAt(index); comments.Insert(indexChildren, changeParrentPosition); } foreach (var item in comments) { CommentsViewModel commentsViewModel = new CommentsViewModel { Name = item.Name, Text = item.Text, DateInsert = _helpService.TimeAgo(item.DateInsert), Rank = item.Rank, FkParrentComment = item.FkParrentComment, Id = item.Id }; commentsMap.Add(commentsViewModel); } return(commentsMap); }
public ViewViewComponentResult Invoke() { var model = new CommentsViewModel(); model.Comments = _commentService.GetCommentsByCurrentUser(); return(View(model)); }
public ActionResult CommentsList(CommentsViewModel model, CommentViewModel newComment, string action) { if (action != null) { var comments = model.Comments; if (action.ToLower().StartsWith("delete")) { var delete = int.Parse(action.Substring(7)); comments = comments.Take(delete).Concat(comments.Skip(delete + 1).Take(comments.Count() - 1 - delete)); } if (action.ToLower().StartsWith("add")) { if (comments == null) { comments = new CommentViewModel[] { } } ; comments = comments.Concat(new[] { newComment }); } model.Comments = comments; } ViewBag.Users = UserService.GetUsers().Select(user => user.ToViewModel()).ToDictionary(x => x.Id, x => x.FullName); return(View("CommentsList", model)); }
protected override DriverResult Display(CRMCommentsPart part, string displayType, dynamic shapeHelper) { CommentsViewModel model = new CommentsViewModel(); model.Id = part.Record.Id; model.CurrentUser = this.services.WorkContext.CurrentUser; model.ContentItemId = part.ContentItem.Id; model.CommentsCount = part.Record.CommentsCount; if (displayType == "TableRow" || displayType == "Summary" || displayType == "SummaryAdmin" || part.Record.Id == default(int)) { return(ContentShape("Parts_CRMComments_Summary", () => shapeHelper.Parts_CRMComments_Summary( Model: model ))); } var comments = this.commentPartRecordRepository.Table.Where(c => c.CRMCommentsPartRecord.Id == part.Record.Id).ToList(); var users = this.services.ContentManager.GetMany <IUser>(comments.Where(c => c.User != null).Select(c => c.User.Id), VersionOptions.Published, QueryHints.Empty); foreach (var record in comments) { model.Comments.Add(this.Convert(record, users)); } var result = new List <DriverResult>(); result.Add(ContentShape("Parts_CRMComments", () => shapeHelper.Parts_CRMComments(Model: model))); result.Add(ContentShape("Parts_CRMComments_Header", () => shapeHelper.Parts_CRMComments_Header(Model: model))); return(Combined(result.ToArray())); }
public ActionResult AddComment(CommentsViewModel model) { if (ModelState.IsValid) { if (_unitOfWork.Games.GetByKey(model.GameKey) == null) { throw new InvalidOperationException($"Game with ID={model.GameKey} was not found in the DB"); } var comment = _mapper.Map <Comment>(model); if (comment.ParentCommentKey != null) { Comment parentComment = _unitOfWork.Comments.GetByKey(comment.ParentCommentKey); comment.Body = comment.Body.Insert(0, "[" + parentComment.Name + "] "); } _unitOfWork.Comments.Insert(comment); _unitOfWork.Save(); return(RedirectToAction("Comments", new { key = model.GameKey })); } model.AllComments = _unitOfWork.Comments.GetCommentsByGame(model.GameKey); return(View("Comments", model)); }
public ViewResult Comments(string key) { var model = new CommentsViewModel(); model.AllComments = _unitOfWork.Comments.GetCommentsByGame(key); model.GameKey = key; return(View(model)); }
public TrailPage(string id) { trailId = id; var trail = DbQueryAsync.GetTrailById(id); BindingContext = new CommentsViewModel(trailId); Content = GenerateMainGrid(trail); }
public ActionResult AddComment(CommentsViewModel comment, int landmarkId) { var userId = this.User.GetUserId(); this._service.SaveComment(userId, landmarkId, comment); return(RedirectToAction("GetComments", "Comments", new { landmarkId = landmarkId })); }
public ActionResult Comments() { var viewModel = new CommentsViewModel(); viewModel.CommentBanks = _context.CommentBanks.OrderBy(x => x.Name).ToList(); return(View(viewModel)); }
public CommentsPage(int Id) // TopicId { InitializeComponent(); _id = Id; BindingContext = model = new CommentsViewModel(); this.Title = "Comments"; NavigationPage.SetHasBackButton(this, true); }
public CommentsPage(CommentsViewModel commentsViewModel, int complexStringId) { BindingContext = commentsViewModel; InitializeComponent(); commentsViewModel.Initialize(complexStringId); }
// GET: Guest public ActionResult Index() { var comments = _commentsSerice.GetComments(); var viewModel = new CommentsViewModel(); viewModel.Commets = comments; return(View(viewModel)); }
public ActionResult GetByPage(int tutorialId, int page) { var result = new CommentsViewModel(); result.Comments = this.comments.GetByPage(tutorialId, page).To<CommentViewModel>().ToList(); result.Pages = this.comments.GetPagesCount(tutorialId); return this.PartialView("_CommentsPartial", result); }
public ActionResult Add(int tutorialId, int page, CommentCreateViewModel model) { this.comments.Add(model.Content, User.Identity.GetUserId(), tutorialId); var result = new CommentsViewModel(); result.Comments = this.comments.GetByPage(tutorialId, page).To<CommentViewModel>().ToList(); result.Pages = this.comments.GetPagesCount(tutorialId); return this.PartialView("_CommentsPartial", result); }
public PartialViewResult BaseScoreCardComments(CommentsViewModel model) { model.CommentedBaseScoreCards = baseScoreCardRepository.Find(model.ToFilter()); return PartialView(model); }
/// <summary> /// Metoda NavigationHelper'a. Pobiera dane przekazywane z widoku źródłowego (DevicesPage). /// deviceId jest argumentem przekazywanym z widoku Produktów. /// Następnie ładowany jest ViewModel DevicesViewModel by pobrać nazwę urządzenia (w celu wyświetlenia jako nagłówek strony) /// Komentarze dla danego produkty są pobierane z bazy danych oraz przypisywane do listy i wyświetlane. /// </summary> /// <param name="e"></param> protected override void OnNavigatedTo(NavigationEventArgs e) { navigationHelper.OnNavigatedTo(e); var deviceID = (long)e.Parameter; var commViewModel = DevicesViewModel.GetDefault(); pageTitle.Text = commViewModel.GetItem(deviceID).Name; if (viewModel != null && (deviceID == viewModel.DeviceId) && (timestamp >= viewModel.Timestamp)) return; viewModel = CommentsViewModel.GetForDeviceId(deviceID); CommentsList.ItemsSource = viewModel.GetAllItems(); timestamp = DateTime.Now; }
public ActionResult Comments(int ProblemID, int TournamentID = -1) { int userID = WebSecurity.CurrentUserId; bool showAll; IEnumerable<Comment> comments = _getComments(ProblemID, out showAll, TournamentID); CommentsViewModel viewModel = new CommentsViewModel() { ProblemID = ProblemID, TournamentID = TournamentID, ShowAll = showAll }; viewModel.Comments = new List<CommentViewModel>(); Stack<Comment> stack = new Stack<Comment>(comments.OrderByDescending(c => c.Date)); Comment temp; bool showAllBranch = false; while (stack.Count > 0) { temp = stack.Pop(); viewModel.Comments.Add(new CommentViewModel(temp, temp.IsRead == 0)); // Mark as read if (temp.IsRead != 1 && temp.UserID != userID) { //if (temp.ParentComment == null) //{ // if (!Roles.IsUserInRole("Administrator") || viewModel.ShowAll) // temp.IsRead = 1; //} //else //{ // temp.IsRead = temp.ParentComment.UserID == userID ? 1 : 0; //} if (temp.ParentComment != null) temp.IsRead = temp.ParentComment.UserID == userID ? 1 : 0; } repository.AddComment(temp); showAllBranch = temp.Level == 0 ? temp.UserID == WebSecurity.CurrentUserId : showAllBranch; if (Roles.IsUserInRole("Administrator") || viewModel.ShowAll || temp.UserID == userID || showAllBranch) { temp.ChildComments.OrderByDescending(c => c.Date).Each(c => stack.Push(c)); } else if (temp.Public == 1) { temp.ChildComments.Where(c => c.Public == 1 || c.UserID == WebSecurity.CurrentUserId).OrderByDescending(c => c.Date).Each(c => stack.Push(c)); } } return View(viewModel); }
public PartialViewResult ValuationScoreCardComments(CommentsViewModel model) { model.CommentedValuationScoreCards = valuationScoreCardRepository.Find(model.ToFilter()); return PartialView(model); }