Esempio n. 1
0
        public List <GetCommentViewModels> GetComments(Post post)
        {
            List <Comment> comments = db.Comments.
                                      Where(x => x.PostID == post.Id).OrderByDescending(x => x.PostedAt).ToList();
            var userIDs = comments.Select(x => x.Author);
            List <ApplicationUser> users = db.Users
                                           .Where(x => userIDs.Contains(x.Id)).ToList();

            List <GetCommentViewModels> model = new List <GetCommentViewModels>();

            foreach (var item in comments)
            {
                var commentuser = users.SingleOrDefault(x => x.Id == item.Author);
                var input       = new GetCommentViewModels();
                input.User              = commentuser;
                input.Comment           = item;
                input.ConvertedDateTime = item.PostedAt.ToString();
                model.Add(input);
            }
            return(model);
        }
Esempio n. 2
0
        public IActionResult Gets(string CustomerId)
        {
            var Gets       = DB.Comments.Where(w => w.CustomerId == CustomerId).ToList();
            var User       = DB.Users;
            var Customer   = DB.Customers;
            var ViewModels = new List <GetCommentViewModels>();

            foreach (var Get in Gets)
            {
                var Model = new GetCommentViewModels();
                Model.Title        = Get.Title;
                Model.Comment      = Get.Comment;
                Model.CommentBy    = User.Where(w => w.Id == Get.CommentBy).Select(s => s.FirstName + " " + s.LastName).FirstOrDefault();
                Model.CommentDate  = Helper.getShortDateAndTime(Get.CommentDate);
                Model.CommentId    = Get.CommentId;
                Model.CustomerName = Customer.Where(w => w.CustomerId == Get.CustomerId).Select(s => s.CompanyName).FirstOrDefault();
                ViewModels.Add(Model);
            }

            return(PartialView("Gets", ViewModels));
        }