Ejemplo n.º 1
0
        public IActionResult Upload(TubeUploadBindingModel tube)
        {
            if (!this.User.IsAuthenticated)
            {
                return(RedirectToLogin());
            }

            if (!this.IsValidModel(tube))
            {
                this.Model.Data["error"] = this.GetErrorMessageFromInfalidProp(tube);
                return(this.View());
            }

            var tubeDb = new Tube
            {
                Author      = tube.Author,
                Description = tube.Description,
                Title       = tube.Title,
                UploaderId  = this.Context.Users.FirstOrDefault(u => u.Username == this.User.Name).Id,
                YoutubeId   = tube.YouTubeLink
            };

            using (this.Context)
            {
                this.Context.Tubes.Add(tubeDb);
                this.Context.SaveChanges();
            }

            return(RedirectToHome());
        }
Ejemplo n.º 2
0
        public IActionResult Upload(TubeUploadBindingModel model)
        {
            if (this.ModelState.IsValid)
            {
                var youTubeId = this.GetYouTubeIdFromLink(model.YouTubeLink);

                if (youTubeId == null)
                {
                    return(this.RedirectToAction("Error", "Home"));
                }

                var tube = new Tube
                {
                    Title       = model.Title,
                    Author      = model.Author,
                    Description = model.Description,
                    YouTubeId   = youTubeId,
                    UploaderId  = this.userManager.GetUserId(this.HttpContext.User)
                };

                this.tubeService.Add(tube);
                return(this.RedirectToAction("Details", "Tube", new { id = tube.Id }));
            }


            return(this.View());
        }
Ejemplo n.º 3
0
        public IActionResult Upload(TubeUploadBindingModel model)
        {
            if (!this.IsValidModel(model))
            {
                return(this.BuildErrorView());
            }

            using (this.Context)
            {
                var youTubeId = this.GetYouTubeIdFromLink(model.YouTubeLink);

                if (youTubeId == null)
                {
                    return(this.BuildErrorView());
                }

                var tube = new Tube
                {
                    Title       = model.Title,
                    Author      = model.Author,
                    Description = model.Description,
                    YouTubeId   = youTubeId,
                    UploaderId  = this.DbUser.Id
                };

                this.Context.Tubes.Add(tube);
                this.Context.SaveChanges();

                return(this.RedirectToAction($"/tube/details?id={tube.Id}"));
            }
        }