Exemplo n.º 1
0
 public ActionResult Index()
 {
     using (var db = new MyTubeEntities())
     {
         return(View());
     }
 }
Exemplo n.º 2
0
 public ActionResult Register(RegisterViewModel model)
 {
     if (ModelState.IsValid)
     {
         using (var db = new MyTubeEntities())
         {
             var existEmailAddress = db.Users.Any(x => x.Username == model.EmailAddress);
             if (existEmailAddress)
             {
                 ModelState.AddModelError("ErrorMessage", "This email address is already exist");
                 return(View(model));
             }
             var newUser = new User
             {
                 Username  = model.EmailAddress,
                 Password  = model.Password,
                 CreatedBy = model.EmailAddress,
                 CreatedOn = DateTime.Now,
                 IsActive  = true,
                 RoleId    = 1,
                 Email     = model.EmailAddress
             };
             db.Users.Add(newUser);
             db.SaveChanges();
             FormsAuthentication.SetAuthCookie(model.EmailAddress, true);
             ResetCurrentUserSession(model.EmailAddress);
             return(RedirectToAction("Index", "Home"));
         }
     }
     else
     {
         ModelState.AddModelError("ErrorMessage", "Please complete all the field");
         return(View(model));
     }
 }
Exemplo n.º 3
0
 public ActionResult Register(RegisterViewModel model)
 {
     using (var db = new MyTubeEntities())
     {
         var newUser = new User
         {
             Username     = model.Username,
             EmailAddress = model.EmailAddress,
             Gender       = model.Gender,
             Password     = model.Password,
             CreatedOn    = DateTime.Now,
             //    CreatedBy = CurrentSession.CurrentUser.Id,
             IsAdmin   = false,
             IsActive  = true,
             FirstName = model.FirstName,
             LastName  = model.LastName,
         };
         db.Users.Add(newUser);
         db.SaveChanges();
         FormsAuthentication.SetAuthCookie(model.Username, true);
         //Authorise cookie
         //Generate new session
         ResetCurrentUserSession(model.Username);
         return(RedirectToAction("Index", "Home"));
     }
 }
Exemplo n.º 4
0
 public ActionResult LoadVideoComment(int videoId)
 {
     using (var db = new MyTubeEntities())
     {
         var allComments = db.Comments.Where(x => x.VideoId == videoId).ToList();
         return(PartialView("CommentListPartial", allComments));
     }
 }
Exemplo n.º 5
0
 public ActionResult CheckIfEmailAddressIsExist(string EmailAddress)
 {
     using (var db = new MyTubeEntities())
     {
         var existEmail = db.Users.Any(x => x.Username == EmailAddress);
         return(Json(!existEmail, JsonRequestBehavior.AllowGet));
     }
 }
Exemplo n.º 6
0
 public ActionResult UploadVideo()
 {
     using (var db = new MyTubeEntities())
     {
         var channel = db.Channels.ToList();
         return(View(channel));
     }
 }
Exemplo n.º 7
0
        public ActionResult DisplayVideo(int id)
        {
            using (var db = new MyTubeEntities())
            {
                var video = db.Videos.Find(id);

                return(View(video));
            }
        }
Exemplo n.º 8
0
 public ActionResult Login(LoginViewModel model)
 {
     using (var db = new MyTubeEntities())
     {
         var user = db.Users.Where(x => x.Username == model.UserName && x.Password == model.Password).FirstOrDefault();
         if (user == null)
         {
             ModelState.AddModelError("ErrorMessage", "We can not find your combination");
             return(View(model));
         }
         FormsAuthentication.SetAuthCookie(user.Email, true);
         ResetCurrentUserSession(user.Email);
         return(RedirectToAction("Index", "Home"));
     }
 }
Exemplo n.º 9
0
        //Pull the information from the VIdeo Table
        public ActionResult VideoManagement()
        {
            using (var db = new MyTubeEntities())
            {
                var allvideo = db.Videos
                               .Include(x => x.Channel)
                               .Include(u => u.User)
                               .Where(x => x.UserId == CurrentSession.CurrentUser.Id)
                               .ToList();



                return(View(allvideo));
            }
        }
Exemplo n.º 10
0
        public ActionResult UploadVideo()
        {
            //upload channel for dropbox
            using (var db = new MyTubeEntities())
            {
                var allchannel = db.Channels
                                 .Where(x => x.UserId == CurrentSession.CurrentUser.Id)
                                 .ToList();
                ViewBag.ChannelList = allchannel;
            };



            return(View());
        }
Exemplo n.º 11
0
 public ActionResult AddNewChannel(ChannelViewModel model)
 {
     using (var db = new MyTubeEntities())
     {
         var channel = new Channel
         {
             UserId      = CurrentSession.CurrentUser.Id,
             Name        = model.ChannelName,
             Description = model.ChannelDescription,
             IsActive    = true,
         };
         db.Channels.Add(channel);
         db.SaveChanges();
         return(Json(new { Success = true, NewChannel = new { Id = channel.Id, Name = channel.Name } }));
     }
 }
Exemplo n.º 12
0
 public ActionResult AddComment(int videoId, string comment)
 {
     using (var db = new MyTubeEntities())
     {
         var commentObj = new Comment
         {
             Contents  = comment,
             VideoId   = videoId,
             UserId    = CurrentSession.CurrentUser.Id,
             CreatedBy = CurrentSession.CurrentUser.Id,
             CreatedOn = DateTime.Now,
             IsActive  = true,
         };
         db.Comments.Add(commentObj);
         db.SaveChanges();
         return(Json(new { Success = true }));
     }
 }
Exemplo n.º 13
0
 public ActionResult Register(string username, string password, string emailAddress)
 {
     using (var db = new MyTubeEntities())
     {
         var newUser = new User
         {
             Username  = username,
             Password  = password,
             Email     = emailAddress,
             CreatedOn = DateTime.Now,
             CreatedBy = username,
             IsActive  = true,
             RoleId    = 1,
         };
         db.Users.Add(newUser);
         db.SaveChanges();
         return(View());
     }
 }
Exemplo n.º 14
0
        public static void ResetCurrentUserSession(string userName = null)
        {
            if (string.IsNullOrEmpty(userName))
            {
                userName = System.Web.HttpContext.Current.User.Identity.Name;
            }

            using (var db = new MyTubeEntities())
            {
                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;
            }
        }
Exemplo n.º 15
0
 public ActionResult UploadVideo(VideoViewModel model)
 {
     //logic save video data in video table
     using (var db = new MyTubeEntities())
     {
         var newVideo = new Video
         {
             Title       = model.Name,
             Description = model.Description,
             URL         = model.Url,
             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 }));
     }
 }
Exemplo n.º 16
0
 public ActionResult Login(string username, string password, bool?rememberme)
 {
     using (var db = new MyTubeEntities())
     {
         var existUser = db.Users.Where(x => x.Username == username && x.Password == password).FirstOrDefault();
         if (existUser == null)
         {
             //Return error
             ViewBag.IncorrectLogin = "******";
             return(View());
         }
         else
         {
             FormsAuthentication.SetAuthCookie(username, rememberme ?? false);
             //Authorise cookie
             //Generate new session
             ResetCurrentUserSession(username);
             TempData["Success"] = "Login Successfully .. ";
             return(RedirectToAction("Index", "Home"));
         }
     }
 }
Exemplo n.º 17
0
 public ActionResult CreateNewChannel(ChannelViewModel model)
 {  //logic save channel detail into channel table
     using (var db = new MyTubeEntities())
     {
         var newChannel = new Channel
         {
             UserId             = CurrentSession.CurrentUser.Id,
             ChannelName        = model.Name,
             ChannelDescription = model.Description,
             IsActive           = true,
             CreatedOn          = DateTime.Now,
             CreatedBy          = CurrentSession.CurrentUser.Id,
         };
         db.Channels.Add(newChannel);
         db.SaveChanges();
         return(Json(new
         {
             Success = true,
             ChannelId = newChannel.Id,
             ChannelName = newChannel.ChannelName
         }));
     }
 }