Exemplo n.º 1
0
        //[HttpPost]
        public ActionResult PostComment(int id, string id2)
        {
            if (Session["userId"] == null)
            {
                throw new Exception("uiuiui");
            }
            //return new ContentResult() { Content = "Not Logged in" };

            string usernameString = Session["userId"].ToString();
            //String text = comment.comment;
            int    discriminator = int.Parse(usernameString.Split('-')[0]);
            string username      = usernameString.Split('-')[1];

            //int id = comment.video;

            CommentBll commentBll = new CommentBll();
            int        CommentId  = commentBll.CreateComment(id, usernameString, id2);
            List <MVCPAP.Models.Comment> comments = commentBll.GetCommentsByVideoId(id);

            VideoBll videoBll = new VideoBll();

            //return View("Video", videoBll.GetVideoDataById(id));
            return(new ContentResult()
            {
                Content = CommentId.ToString()
            });
        }
Exemplo n.º 2
0
        public ActionResult VideoPage(int id)
        {
            VideoBll videoBll = new VideoBll();

            Models.Video video = videoBll.GetVideoById(id);
            ViewBag.title = video.title;

            return(View(video));
        }
Exemplo n.º 3
0
        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));
        }
Exemplo n.º 4
0
        // GET: Account
        public ActionResult Index()
        {
            if (Session["userId"] is null)
            {
                return(RedirectToAction("NotFound", "Home", new { id = "User not logged in" }));
            }

            UserBll userBll = new UserBll();

            MVCPAP.Models.User user = userBll.GetUserById(Session["userId"].ToString());

            VideoBll videoBll = new VideoBll();

            ViewBag.videos = videoBll.GetVideosByUserId(Session["userId"].ToString());

            return(View(user));
        }
Exemplo n.º 5
0
        public ActionResult SearchPage(string id)
        {
            if (Request.QueryString.Get("page") != null)
            {
                ViewBag.page = int.Parse(Request.QueryString.Get("page"));
            }
            ViewBag.Search = id;
            ViewBag.title  = "Search Result";
            VideoBll videoBll = new VideoBll();

            //ViewBag.Videos = videoBll.GetVideosSearchByTitle(id);
            if (id == null)
            {
                return(RedirectToAction("NotFound", "Home", new { message = "Search query not specified - Invalid URL" }));
            }

            return(View(videoBll.GetVideosSearchByTitle(id.ToLower())));
        }
Exemplo n.º 6
0
        public ActionResult Index()
        {
            VideoBll videoBll = new VideoBll();

            List <Models.Video> videos = new List <Models.Video>();

            if (Session["userId"] != null)
            {
                string usernameString = Session["userId"].ToString();

                User user = new User();
                user.username      = usernameString.Split('-')[1];
                user.discriminator = int.Parse(usernameString.Split('-')[0]);

                videos = videoBll.GetRecomendedVideos(user);
            }


            return(View(videos));
        }
Exemplo n.º 7
0
        public ActionResult Search(FormCollection collection, string id)
        {
            if (Request.QueryString.Get("page") != null)
            {
                ViewBag.page = int.Parse(Request.QueryString.Get("page"));
            }

            ViewBag.Title  = "Search for " + id;
            ViewBag.Search = id;
            id             = id.ToLower();
            // SqlConnection connection = new SqlConnection(@"Data Source=.\SQLEXPRESS;Initial Catalog=PAP1;Integrated Security=True");

            // SqlDataAdapter dataAdapter = new SqlDataAdapter(
            //"SELECT * FROM Video Where lower(title) Like '%" + id + "%'"
            //+ "Order By (Case When lower(title)='" + id + "' Then 1 When lower(title)='" + id + "%' Then 2 Else 3 End)"

            //, connection);
            // DataSet dataSet = new DataSet();
            // dataAdapter.Fill(dataSet);

            // List<_Video> Videos = new List<_Video>();

            // foreach (DataRow row in dataSet.Tables[0].Rows)
            // {
            //     _Video V = new _Video();
            //     V.id = int.Parse(row["id"].ToString());
            //     V.title = row["title"].ToString();
            //     V.username = row["username"].ToString();
            //     V.discriminator = int.Parse(row["discriminator"].ToString());
            //     V.videoFile = row["videoFile"].ToString();
            //     V.thumbnail = row["thumbnail"].ToString();
            //     Videos.Add(V);
            // }


            VideoBll videoBll = new VideoBll();

            ViewBag.Videos = videoBll.GetVideosSearchByTitle(id);

            return(View());
        }
Exemplo n.º 8
0
        public ActionResult DownvoteVideo(int id)
        {
            if (Session["userId"] is null)
            {
                return(new ContentResult()
                {
                    Content = "Not logged in"
                });
            }
            Models.User user           = new Models.User();
            string      usernameString = Session["userId"].ToString();

            user.discriminator = int.Parse(usernameString.Split('-')[0]);
            user.username      = usernameString.Split('-')[1];

            Models.Video video = new Models.Video();
            video.id = id;

            VideoBll videoBll = new VideoBll();


            if (videoBll.GetVideoUpvotesByVideoId(id).Where(x => x.username == user.username && x.discriminator == user.discriminator).Count() >= 1)
            {
                videoBll.DeleteVideoUpvote(user, video);
            }
            else
            {
                return new ContentResult()
                       {
                           Content = "false"
                       }
            };
            return(new ContentResult()
            {
                Content = "true"
            });
        }
Exemplo n.º 9
0
        public ActionResult PostVideo(HttpPostedFileBase file, Models.Video video, string tags)
        {
            Models.User user = new Models.User();

            user.username      = Session["userId"].ToString().Split('-')[1];
            user.discriminator = int.Parse(Session["userId"].ToString().Split('-')[0]);


            foreach (string tagtext in tags.Split(' ').ToList())
            {
                Models.Tag tag = new Tag();
                tag.text = tagtext;
                video.tags.Add(tag);
            }

            //video.title = Request.QueryString.Get("title");
            //video.description = Request.QueryString.Get("description");
            video.thumbnail = "defaultthumbnail.png";


            if (file != null && file.ContentLength > 0)
            {
                try
                {
                    string path = Path.Combine(Server.MapPath("../videos"),
                                               Path.GetFileName(file.FileName));
                    file.SaveAs(path);
                    ViewBag.Message = "File uploaded successfully";
                    video.videoFile = file.FileName;
                }
                catch (Exception ex)
                {
                    ViewBag.Message        = "ERROR:" + ex.Message.ToString();
                    video.VideoUploadError = "ERROR:" + ex.Message.ToString();
                    return(new ContentResult()
                    {
                        Content = "ERROR:" + ex.Message.ToString()
                    });
                }
            }
            else
            {
                ViewBag.Message        = "You have not specified a file.";
                video.VideoUploadError = "You have not specified a file.";
                return(new ContentResult()
                {
                    Content = "You have not specified a file."
                });
            }


            VideoBll videoBll = new VideoBll();

            video = videoBll.CreateVideo(user, video);
            return(RedirectToAction("VideoPage", "Home", new { id = video.id }));

            return(new ContentResult()
            {
                Content = "Video posted"
            });
        }
Exemplo n.º 10
0
        public ActionResult profile(string id)
        {
            if (!id.Contains("-"))
            {
                Response.Redirect("PageNotFound...");
            }
            int    discriminator = int.Parse(id.Split('-')[0]);
            string username      = id.Split('-')[1];
            //  SqlConnection connection = new SqlConnection(@"Data Source=.\SQLEXPRESS;Initial Catalog=PAP1;Integrated Security=True");

            //  SqlDataAdapter dataAdapter = new SqlDataAdapter(
            //"SELECT * FROM [User] Where username='******' And discriminator=" + discriminator, connection);
            //  DataSet dataSet = new DataSet();
            //  dataAdapter.Fill(dataSet);

            //  if(dataSet.Tables[0].Rows.Count<=0)
            //  {
            //      throw new Exception("User not found");
            //  }

            //  _User user = new _User();
            //  user.email = dataSet.Tables[0].Rows[0]["email"].ToString();
            //  user.username = username;
            //  user.discriminator = discriminator;
            //  user.profilePicture = dataSet.Tables[0].Rows[0]["profilePicture"].ToString();
            //  user.password = dataSet.Tables[0].Rows[0]["password"].ToString();

            UserBll userBll = new UserBll();

            try
            {
                ViewBag.user = userBll.GetUserById(id);
            }
            catch (Exception ex)
            {
                return(RedirectToAction("NotFound", "Home", new { message = ex.Message }));
            }


            // SqlDataAdapter dataAdapter2 = new SqlDataAdapter(
            //"SELECT * FROM Video Where username='******' And discriminator='" + discriminator + "'", connection);
            // DataSet dataSet2 = new DataSet();
            // dataAdapter2.Fill(dataSet2);

            // List<_Video> Videos = new List<_Video>();

            // foreach (DataRow row in dataSet2.Tables[0].Rows)
            // {
            //     _Video V = new _Video();
            //     V.id = int.Parse(row["id"].ToString());
            //     V.title = row["title"].ToString();
            //     V.username = row["username"].ToString();
            //     V.discriminator = int.Parse(row["discriminator"].ToString());
            //     V.videoFile = row["videoFile"].ToString();
            //     V.thumbnail = row["thumbnail"].ToString();
            //     Videos.Add(V);
            // }
            VideoBll videoBll = new VideoBll();

            ViewBag.Videos = videoBll.GetVideosByUserId(id);

            return(View());
        }