public static Models.User GetUser() { YoyoEntities db = new YoyoEntities(); string username = Membership.GetUser().UserName; Models.User u = db.Users.Where(x => x.UserName == username).FirstOrDefault(); return u; }
public JsonResult GetComments(int videoId) { YoyoEntities db = new YoyoEntities(); var comm = from c in db.Comments where c.VideoId == videoId select new CommentDTO { Id = c.Id, Text = c.Text, Username = c.aspnet_Users.UserName, Date = c.Date, Photo=c.aspnet_Users.Picture.Link }; return Json(comm.ToList()); }
public JsonResult GetComment(int id) { YoyoEntities db = new YoyoEntities(); var comm = from c in db.Comments where c.Id == id select new CommentDTO { Id = c.Id, Text = c.Text, Username = c.aspnet_Users.UserName, Date = c.Date, Photo = c.aspnet_Users.Picture.Link }; return Json(new {comment=comm.FirstOrDefault() }); }
public JsonResult VideoPlayed(int id) { string userId = ""; if (Request.Cookies["userId"] == null) { if (!User.Identity.IsAuthenticated) { userId = Guid.NewGuid().ToString(); } else { userId = Membership.GetUser().ProviderUserKey.ToString(); } HttpCookie c = new HttpCookie("userId"); c.Expires=DateTime.Now.AddDays(60); c.Value = userId; Response.Cookies.Add(c); } else{ userId = Request.Cookies["userId"].Value; } YoyoEntities db = new YoyoEntities(); Guid uid = new Guid(userId); if (db.Ratings.Where(x => x.UserId == uid & x.VideoId == id).FirstOrDefault() == null) { Rating r = new Rating(); r.VideoId = id; r.UserId = uid; r.Date = DateTime.Now; db.Ratings.Add(r); db.SaveChanges(); } return Json(1); }
public JsonResult SendComment(string com, int videoId) { Comment c = new Comment(); c.Text = com; c.VideoId = videoId; c.UserId = Helper.GetUser().UserId; c.Date = DateTime.Now; YoyoEntities db = new YoyoEntities(); db.Comments.Add(c); db.SaveChanges(); return Json(new { commentId = c.Id }); }