//[Authorize(Roles = "Admin")] public ActionResult Ban(int id) { if (User.IsInRole("Regular")) { return(RedirectToAction("Unauthorized", "Account")); } using (treca_aplikacija_model db = new treca_aplikacija_model()) { return(View(ApplicationUtils.CreateVideoViewModel(db.videos.Find(id)))); } }
public ActionResult Delete(byte?id) { using (treca_aplikacija_model db = new treca_aplikacija_model()) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } video video = db.videos.Find(id); if (video == null) { return(HttpNotFound()); } return(View(ApplicationUtils.CreateVideoViewModel(video))); } }
public ActionResult Administrator(string query, bool isUser) { List <Object> retVal = new List <Object>(); using (treca_aplikacija_model db = new treca_aplikacija_model()) { if (isUser) { foreach (var x in db.users.Where(x => x.user_username.Contains(query)).ToList()) { retVal.Add(ApplicationUtils.CreateUserViewModelDTO(x)); } } else { foreach (var x in db.videos.Where(x => x.video_name.Contains(query)).ToList()) { retVal.Add(ApplicationUtils.CreateVideoViewModel(x)); } } return(Json(new { returnValues = retVal }, JsonRequestBehavior.AllowGet)); } }
public ActionResult Filter(string userFilter, string lowDateFilter, string highDateFilter) { Debug.WriteLine("UserF: " + userFilter); Debug.WriteLine("LowDF: " + lowDateFilter); Debug.WriteLine("HighF: " + highDateFilter); treca_aplikacija_model db = new treca_aplikacija_model(); List <VideoViewModel> videosDTO = new List <VideoViewModel>(); if (userFilter == null && lowDateFilter == null & highDateFilter == null) { return(Json(new { message = "Everyting is null" }, JsonRequestBehavior.AllowGet)); } else { List <VideoViewModel> videos = new List <VideoViewModel>(); if (userFilter != null) { foreach (var x in db.videos.Include(v => v.user).Where(x => x.user.user_username.Equals(userFilter)).ToList()) { videos.Add(ApplicationUtils.CreateVideoViewModel(x)); } //videos += db.videos.Include(v => v.user).Include(v => v.comments).Where(x => x.user.user_username.Contains(userFilter)).ToList(); } if (lowDateFilter != null && highDateFilter != null) { foreach (var x in db.videos.Include(v => v.user).ToList()) { if (x.video_created > DateTime.Parse(lowDateFilter) && x.video_created < DateTime.Parse(highDateFilter)) { videos.Add(ApplicationUtils.CreateVideoViewModel(x)); } } //videos += db.videos.Include(v => v.user).Include(v => v.comments).Where(x => x.video_created > Convert.ToDateTime(lowDateFilter) && x.video_created < Convert.ToDateTime(highDateFilter) ).ToList(); } else { if (lowDateFilter != null) { foreach (var x in db.videos.Include(v => v.user).ToList()) { if (x.video_created > DateTime.Parse(lowDateFilter)) { videos.Add(ApplicationUtils.CreateVideoViewModel(x)); } } //List<video> videos = db.videos.Include(v => v.user).Include(v => v.comments).Where(x => x.video_created > Convert.ToDateTime(lowDateFilter)).ToList(); } else if (highDateFilter != null) { foreach (var x in db.videos.Include(v => v.user).ToList()) { if (x.video_created < DateTime.Parse(highDateFilter)) { videos.Add(ApplicationUtils.CreateVideoViewModel(x)); } } //List<video> videos = db.videos.Include(v => v.user).Include(v => v.comments).Where(x => x.video_created > Convert.ToDateTime(lowDateFilter)).ToList(); } } return(Json(new { Videos = videos.Distinct().ToList() }, 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))); }