Beispiel #1
0
 public void GetPosts(int DemId)
 {
     using (Entities db = new Entities())
     {
         var ret = (from post in db.Comments.Where(d => d.DemotivatorId == DemId).ToList()
                    orderby post.Date
                    select new
                    {
                        Message = post.Text,
                        PostedBy = post.UserId,
                        PostedByName = post.AspNetUsers.UserName,
                        PostedByAvatar = post.AspNetUsers.AvatarUrl,
                        PostedDate = TimeAgo(post.Date),
                        //PostId = post.Id,
                    }).ToArray();
         Clients.All.loadPosts(ret, DemId);
     }
 }
Beispiel #2
0
        public void AddPost(Comments post, string UserId, int DemId1)
        {
            post.UserId = UserId;
            post.Date = DateTime.Now;
            post.DemotivatorId = DemId1;
            using (Entities db = new Entities())
            {
                db.Comments.Add(post);
                db.SaveChanges();
                var usr = db.AspNetUsers.FirstOrDefault(x => x.Id == post.UserId);
                var ret = new
                {
                    Message = post.Text,
                    PostedBy = post.UserId,
                    PostedByName = usr.UserName,
                    PostedByAvatar = post.AspNetUsers.AvatarUrl,
                    PostedDate = TimeAgo(post.Date),
                    //PostId = post.Id
                };

                Clients.Caller.addPost(ret);
                Clients.Others.newPost(ret, DemId1);
            }
        }
 public ActionResult Index()
 {
     DemoTagsViewModel model = new DemoTagsViewModel();
     using (var context = new Entities())
     {
         model.demoList = context.Demotivators.ToList();
         model.tagsList = context.Tags.ToList();
     }
     return View(model);
 }