Example #1
0
        public IActionResult Upload(UploadTubeViewModel model)
        {
            if (!this.IsValidModel(model))
            {
                this.ShowError("Invalid tube details.");
                return(this.View());
            }

            var title       = model.Title;
            var author      = model.Author;
            var youtubeId   = this.GetYouTubeIdFromLink(model.YoutubeLink);
            var description = model.Description;
            var userId      = this.CurrentUser.Id;

            if (youtubeId == null)
            {
                this.ShowError("Invalid youtube link.");
                return(this.View());
            }

            var success = this.tube.Upload(title, author, youtubeId, description, userId);

            if (!success)
            {
                this.ShowError("Tube already exists.");
                return(this.View());
            }

            return(this.RedirectToHome());
        }
Example #2
0
        public IActionResult Upload(UploadTubeViewModel model)
        {
            if (!this.IsValidModel(model))
            {
                this.Model.Data["error"] = this.ParameterValidator.FirstErrorMessage;

                return(View());
            }

            var tube = new Tube
            {
                Author      = model.Author,
                Description = model.Description,
                Title       = model.Title,
                Uploader    = this.Db.Users.FirstOrDefault(u => u.Username == this.User.Name),
                YoutubeId   = model.YoutubeLink.Split("?v=").Last()
            };

            Db.Add(tube);
            Db.SaveChanges();

            return(this.RedirectToHome());
        }