Ejemplo n.º 1
0
 public ActionResult LoadVideoComment(int videoId)
 {
     using (var db = new MyUtubeDatabaseEntities())
     {
         var allComments = db.Comments.Where(x => x.VideoId == videoId).ToList();
         return(PartialView("CommentListPartial", allComments));
     }
 }
Ejemplo n.º 2
0
 public ActionResult Index()
 {
     using (var db = new MyUtubeDatabaseEntities())
     {
         var allVideo = db.Videos.Where(x => x.IsActive).ToList();
         return(View(allVideo));
     }
 }
Ejemplo n.º 3
0
 public ActionResult DisplayVideo(int id)
 {
     using (var db = new MyUtubeDatabaseEntities())
     {
         var video = db.Videos.Find(id);
         return(View(video));
     }
 }
Ejemplo n.º 4
0
        public ActionResult VideoManagement()
        {
            using (var db = new MyUtubeDatabaseEntities())
            {
                var allVideo = db.Videos.Include(x => x.Channel)
                               .Where(x => x.UserId == CurrentSession.CurrentUser.Id).ToList();

                return(View(allVideo));
            }
        }
Ejemplo n.º 5
0
 public ActionResult UploadVideo()
 {
     using (var db = new MyUtubeDatabaseEntities())
     {
         //TODO find all channel of current user
         //ToDO add to ViewBag.ChannelList
         // go to the view
         var allChannel =
             db.Channels.Where(x => x.UserId == CurrentSession.CurrentUser.Id).ToList();
         ViewBag.ChannelList = allChannel;
         return(View());
     }
 }
Ejemplo n.º 6
0
 public ActionResult AddComment(int videoId, string comment)
 {
     using (var db = new MyUtubeDatabaseEntities())
     {
         var commentObj = new Comment
         {
             Content = comment,
             VideoId = videoId,
             UserId  = CurrentSession.CurrentUser.Id,
             //Cr = CurrentSession.CurrentUser.Id,
             //CreatedOn = DateTime.Now,
             //IsActive = true,
         };
         db.Comments.Add(commentObj);
         db.SaveChanges();
         return(Json(new { Success = true }));
     }
 }
Ejemplo n.º 7
0
        public static void ResetCurrentUserSession(string userName = null)
        {
            if (string.IsNullOrEmpty(userName))
            {
                userName = System.Web.HttpContext.Current.User.Identity.Name;
            }

            using (var db = new MyUtubeDatabaseEntities())
            {
                var user = db.Users.FirstOrDefault(n => n.Username == userName);
                // modified for forgot password
                if (user == null)
                {
                    return;
                }
                // Generic of CurrentUser that can user across system
                CurrentSession.CurrentUser = user;
            }
        }
Ejemplo n.º 8
0
 public ActionResult UploadVideo(VideoViewModel model)
 {
     using (var db = new MyUtubeDatabaseEntities())
     {
         var newVideo = new Video
         {
             Name        = model.VideoName,
             Description = model.VideoDescription,
             URL         = model.VideoUrl,
             ChannelId   = model.ChannelDropDown,
             UserId      = CurrentSession.CurrentUser.Id,
             CreatedOn   = DateTime.Now,
             CreatedBy   = CurrentSession.CurrentUser.Id,
             IsActive    = true
         };
         db.Videos.Add(newVideo);
         db.SaveChanges();
         return(Json(new { Success = true, VideoId = newVideo.Id }));
     }
 }
Ejemplo n.º 9
0
 public ActionResult CreateNewChannel(ChannelViewModel model)
 {
     using (var db = new MyUtubeDatabaseEntities())
     {
         var newChannel = new Channel
         {
             Name        = model.ChannelName,
             Description = model.ChannelDescription,
             UserId      = CurrentSession.CurrentUser.Id
         };
         db.Channels.Add(newChannel);
         db.SaveChanges();
         return(Json(new
         {
             Success = true,
             ChannelId = newChannel.Id,
             ChannelName = newChannel.Name
         }));
     }
 }
Ejemplo n.º 10
0
        public ActionResult Login(LoginViewModel model)
        {
            //logic compare want username / password with User table

            using (var db = new MyUtubeDatabaseEntities())
            {
                var existUser = db.Users.Where(x => x.Username == model.Username &&
                                               x.Password == model.Password).FirstOrDefault();
                if (existUser == null)
                {
                    ViewBag.IncorrectLogin = "******";
                    return(View());
                }
                else
                {
                    FormsAuthentication.SetAuthCookie(model.Username, false);
                    ResetCurrentUserSession(model.Username);
                    return(RedirectToAction("Index", "Home"));
                }
            }
        }
Ejemplo n.º 11
0
        public ActionResult Register(RegisterViewModel model)
        {
            //logic saving register detail in the User table

            using (var db = new MyUtubeDatabaseEntities())
            {
                var newUser = new User
                {
                    Username  = model.Username,
                    Email     = model.Email,
                    Password  = model.Password,
                    CreatedOn = DateTime.Now,
                    IsActive  = true,
                };
                db.Users.Add(newUser);
                db.SaveChanges();
                //save the cookie in browers
                FormsAuthentication.SetAuthCookie(model.Username, true);
                ResetCurrentUserSession(model.Username);

                return(RedirectToAction("Index", "Home"));
            }
        }