public IActionResult Edit(int genreClipsId, [Bind("GenreClipsId,GenreName2")] GenreClips genreClips)
        {
            if (genreClipsId != genreClips.GenreClipsId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    repo.Save(genreClips);
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!GenreClipsExists(genreClips.GenreClipsId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(genreClips));
        }
        public IActionResult Create([Bind("GenreClipsId,GenreName")] GenreClips genreClips)
        {
            if (ModelState.IsValid)
            {
                repo.Save(genreClips);

                return(RedirectToAction(nameof(Index)));
            }
            return(View(genreClips));
        }
예제 #3
0
        public void Save(GenreClips g)
        {
            if (g.GenreClipsId == 0)
            {
                _context.GenreClips.Add(g);
            }
            else
            {
                _context.GenreClips.Update(g);
            }

            _context.SaveChanges();
        }
예제 #4
0
        public static void Initialize(IServiceProvider serviceProvider)
        {
            using (var context = new WatchFunnyClipContext(
                       serviceProvider.GetRequiredService <
                           DbContextOptions <WatchFunnyClipContext> >()))
            {
                // You add more code here to seed database.
                // See: https://docs.microsoft.com/en-us/aspnet/core/tutorials/first-mvc-app/working-with-sql?view=aspnetcore-3.0&tabs=visual-studio
                if (!context.GenreClips.Any())
                {
                    var genreClips = new GenreClips[] {
                        new GenreClips {
                            GenreName = "Animal"
                        },
                        new GenreClips {
                            GenreName = "Baby"
                        },
                        new GenreClips {
                            GenreName = "Sport"
                        },
                        new GenreClips {
                            GenreName = "Random"
                        }
                    };

                    context.GenreClips.AddRange(genreClips);
                    //foreach(var spec in species)
                    //{
                    //    context.Species.Add(spec);
                    //}

                    context.SaveChanges();
                }

                if (!context.Clip.Any())
                {
                    var genreClipsType = context.GenreClips.ToList();

                    var clips = new Clip[]
                    {
                        new Clip {
                            Title = "Man Whip himself", Description = "Funny man", Url = "https://www.youtube.com/embed/uMGBvcGBZL8", GenreClipsId = 3
                        },
                    };
                    context.Clip.AddRange(clips);


                    context.SaveChanges();
                }
            }
        }
예제 #5
0
        public void CreatePost_ReturnsViewWithGenreClips_WhenModelStateIsInvalid()
        {
            // Arrange
            var mockRepo   = new Mock <IGenreClipsRepository>();
            var controller = new GenreClipsController(mockRepo.Object);

            controller.ModelState.AddModelError("GenreName", "Required");
            var genreClips = new GenreClips()
            {
                GenreName = ""
            };

            // Act
            var result = controller.Create(genreClips);

            // Assert
            var viewResult = Assert.IsType <ViewResult>(result);
            var model      = Assert.IsAssignableFrom <GenreClips>(viewResult.ViewData.Model);

            Assert.IsType <GenreClips>(model);
        }
예제 #6
0
        public void CreatePost_SaveThroughRepository_WhenModelStateIsValid()
        {
            // Arrange
            var mockRepo = new Mock <IGenreClipsRepository>();

            mockRepo.Setup(repo => repo.Save(It.IsAny <GenreClips>()))
            //.Returns(Task.CompletedTask)
            .Verifiable();
            var        controller = new GenreClipsController(mockRepo.Object);
            GenreClips g          = new GenreClips()
            {
                GenreName = "Animal",
            };

            // Act
            var result = controller.Create(g);

            // Assert
            var redirectToActionResult = Assert.IsType <RedirectToActionResult>(result);

            Assert.Null(redirectToActionResult.ControllerName);
            Assert.Equal("Index", redirectToActionResult.ActionName);
            mockRepo.Verify();
        }