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 }); }