public ActionResult DeleteConfirmed(string username) { //Delete applicationUser //Delete databaserUser Debug.WriteLine(username); int userId = ApplicationUtils.FindUserByUsername(username).users_id; string loggedInUserUsername = User.Identity.GetApplicationUserUsername(); if (loggedInUserUsername.Equals(username)) { AuthenticationManager.SignOut(DefaultAuthenticationTypes.ApplicationCookie); UserManager.Delete(UserManager.FindByEmail((ApplicationUtils.FindUserByUsername(username)).user_email)); } using (treca_aplikacija_model db = new treca_aplikacija_model()) { db.Database.ExecuteSqlCommand("DELETE FROM comment_like_dislike WHERE users_id = {0}", userId); db.Database.ExecuteSqlCommand("DELETE FROM video_like_dislike WHERE users_id = {0}", userId); db.Database.ExecuteSqlCommand("DELETE FROM users_role WHERE users_id = {0}", userId); db.Database.ExecuteSqlCommand("DELETE FROM users_following WHERE user_following = {0} or user_followed = {1}", userId, userId); db.Database.ExecuteSqlCommand("DELETE FROM comment WHERE comment_user_id = {0}", userId); db.Database.ExecuteSqlCommand("DELETE FROM comment WHERE comment_video_id IN (SELECT video_id FROM video WHERE video_user_id = {0})", userId); //db.Database.ExecuteSqlCommand("DELETE FROM comment WHERE video_id = SELEC", userId); db.Database.ExecuteSqlCommand("DELETE FROM video WHERE video_user_id = {0}", userId); db.Database.ExecuteSqlCommand("DELETE FROM users WHERE users_id = {0}", userId); } return(RedirectToAction("Index", "Video")); }
public ActionResult SubmitLikeDislike(int videoId, bool isLike) { if (!User.Identity.IsAuthenticated) { return(Json(new { message = "redirect" }, JsonRequestBehavior.AllowGet)); } using (treca_aplikacija_model db = new treca_aplikacija_model()) { UserViewModel user = ApplicationUtils.FindUserByUsername(User.Identity.GetApplicationUserUsername()); try { ApplicationUtils.RemoveLikeDislike(true, videoId, user.users_id); } catch (Exception) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } video_like_dislike newVld = new video_like_dislike(); newVld.users_id = (byte)user.users_id; newVld.video_id = (byte)videoId; newVld.is_like = isLike == true ? true : false; db.video_like_dislike.Add(newVld); db.SaveChanges(); } return(Json(new { Success = true }, JsonRequestBehavior.AllowGet)); }
public ActionResult RemoveLikeDislike(int videoId) { using (treca_aplikacija_model db = new treca_aplikacija_model()) { UserViewModel user = ApplicationUtils.FindUserByUsername(User.Identity.GetApplicationUserUsername()); try { ApplicationUtils.RemoveLikeDislike(true, videoId, user.users_id); } catch (Exception) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } } return(Json(new { Success = true }, JsonRequestBehavior.AllowGet)); }
// GET: Video/Details/5 // GET: Video/Details/5?page=x&sort=y public ActionResult Details(byte?id, int?page = 1, string sort = "Created", bool initial = true) { if (!initial) { ViewBag.Scroll = true; } else { ViewBag.Scroll = false; } ViewBag.CurrentCommentPage = page; ViewBag.CurrentCommentSortParam = sort; if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } treca_aplikacija_model db = new treca_aplikacija_model(); video video = db.videos.Find(id); if (video == null) { return(HttpNotFound()); } UserViewModel user = ApplicationUtils.FindUserByUsername(User.Identity.GetApplicationUserUsername()); if (user != null) { foreach (var x in db.video_like_dislike) { if (x.users_id == user.users_id && x.video_id == video.video_id) { ViewBag.LikeDislikeEntity = x; } } ViewBag.UserCommentLikeDislike = db.comment_like_dislike.Where(x => x.users_id == user.users_id && x.comment.comment_video_id == id).ToList(); } //Initial pagination int numOfComments = video.comments.Count(); int paginationNumber = 0; if (numOfComments > 5) { paginationNumber = (numOfComments / 5) + 1; } else { paginationNumber = 1; } ViewBag.CommentPagination = paginationNumber; //Pagination and sort param List <comment> comments = new List <comment>(); if (sort.Equals("Created")) { comments = video.comments.OrderByDescending(x => x.comment_created).ToList(); } else { foreach (var x in video.comments) { x.comment_rating = x.comment_like_dislike.Where(z => z.is_like).Count() - x.comment_like_dislike.Where(z => !z.is_like).Count(); Debug.WriteLine("Comment content:" + x.comment_content + "Assigned rating: " + x.comment_rating); } comments = video.comments.OrderByDescending(x => x.comment_rating).ToList(); } if (page == 1) { try { comments = comments.GetRange(0, 5); } catch { comments = comments.GetRange(0, comments.Count()); } } else { try { // comments = comments.GetRange((((int)page - 1) * 5), 5); } catch (ArgumentException) { Debug.WriteLine(video.comments.ToList().Count()); comments = comments.GetRange((((int)page - 1) * 5), comments.Count() / 5); } } video.comments = comments; return(View(ApplicationUtils.CreateVideoViewModel(video))); }