Exemple #1
0
        public IActionResult Upload(TubeBindingModel model)
        {
            if (!this.IsValidModel(model))
            {
                return(View());
            }
            var youtubeId = model.YoutubeLink.Split("?v=")[1];
            var username  = this.User.Name;
            var user      = this.service.GetUserByName(username);

            if (user == null)
            {
                return(RedirectToAction("/account/login"));
            }

            var tube = new Tube()
            {
                Title       = model.Title,
                Author      = model.Author,
                Description = model.Description,
                YoutubeId   = youtubeId,
                User        = user,
                UserId      = user.Id
            };

            this.service.CreateTube(tube);

            return(RedirectToAction("/"));
        }
Exemple #2
0
        public IActionResult Upload(TubeBindingModel model)
        {
            // 1. Validation
            if (!this.IsValidModel(model)) // check the attributes of the model
            {
                this.Model.Data["error"] = "Invalid username and/or password";
                return(this.View());
            }

            // 2. Create new user with Hash password and Add user to DB:
            var userId = this.userBusinessService.GetUsersId(this.User.Name);
            var tube   = this.tubeBusinessService.Register(
                model.Title, model.Author, model.YoutubeLink, model.Description, userId);

            // 3. Login the user so session:
            if (tube)
            {
                return(this.RedirectToAction("/home/index")); // ????? WHERE to redirect?
                // may be to details page ?! - try do this
            }

            this.Model.Data["error"] = "Invalid data input";
            return(View());
        }