Beispiel #1
0
        public ActionResult Genres()
        {
            AdminGenresViewModel viewModel = new AdminGenresViewModel
            {
                Genres           = context.Genres.ToList(),
                CreateGenreModel = new Genre()
            };

            return(View(viewModel));
        }
Beispiel #2
0
 public IActionResult GenreCreate(AdminGenresViewModel model)
 {
     if (model.Name != null && model.Name.Length < 3)
     {
         ModelState.AddModelError("Name", "Tür Adı Minimum 3 karakterde olmalıdır.");
     }
     if (ModelState.IsValid)
     {
         _context.Genres.Add(new Genre {
             Name = model.Name
         });
         _context.SaveChanges();
         return(RedirectToAction("GenreList"));
     }
     return(View("GenreList", GetGenres()));
 }
        //Genre
        public IActionResult GenreList()
        {
            var model = new AdminGenresViewModel
            {
                Genres = context.Genres
                         .Select(g => new AdminGenreViewModel
                {
                    GenreId = g.GenreId,
                    Name    = g.Name,
                    Count   = g.Movies.Count
                })
                         .ToList()
            };

            return(View(model));
        }