public ActionResult Video(int id) { ViewBag.id = id; VideoBll videoBll = new VideoBll(); Models.VideoData video = videoBll.GetVideoDataById(id); if (id == null || id < 0 || video is null) { return(RedirectToAction("NotFound", "Home", new { message = "Could not find that video" })); } ViewBag.loggedin = 0; string usernameString = "0000-user"; if (Session["userId"] != null) { usernameString = Session["userId"].ToString(); ViewBag.loggedin = 1; } int discriminator = int.Parse(usernameString.Split('-')[0]); string username = usernameString.Split('-')[1]; if (video.upvotes.Where(x => x.username == username && x.discriminator == discriminator).Count() >= 1) { video.Upvoted = true; ViewBag.upvoted = 1; } else { video.Upvoted = false; ViewBag.upvoted = 0; } //CommentBll commentBll = new CommentBll(); //List<Models.Comment> comments = commentBll.GetCommentsByVideoId(int.Parse(id)); //ViewBag.Comments = commentBll.GetCommentsByVideoId(int.Parse(id)); //Models.VideoComments videoComments = new Models.VideoComments(); //videoComments.video = video; //videoComments.comments = comments; return(View(video)); }
public Models.VideoData GetVideoDataById(int id) { SqlConnection connection = new SqlConnection(Properties.Settings.Default.Connection); SqlDataAdapter dataAdapter = new SqlDataAdapter( " SELECT Top(1) " + " v.id, v.title, v.description, v.username, v.discriminator, v.videoFile, v.thumbnail, v.publishedAt, COUNT(vu.username)'upVotes' " + " FROM Video v " + " left Join VideoUpvotes vu on vu.video = v.id " + " Where v.id = " + id + " Group by v.id, v.title, v.description, v.username, v.discriminator, v.videoFile, v.thumbnail, v.publishedAt ", connection); DataSet dataSet = new DataSet(); dataAdapter.Fill(dataSet); if (dataSet.Tables.Count <= 0) { return(null); } if (dataSet.Tables[0].Rows.Count <= 0) { return(null); } DataRow row = dataSet.Tables[0].Rows[0]; Models.VideoData video = new Models.VideoData(); video.id = id; video.title = row["title"].ToString(); video.description = row["description"].ToString(); video.username = row["username"].ToString(); video.discriminator = int.Parse(row["discriminator"].ToString()); video.videoFile = row["videoFile"].ToString(); video.thumbnail = row["thumbnail"].ToString(); video.publishedAt = DateTime.Parse(row["publishedAt"].ToString()); video.upVotes = int.Parse(row["upVotes"].ToString()); return(video); }