public IActionResult Create(Movie movie)
        {
            //check if slug is available, else with releaseyear else random
            if (string.IsNullOrWhiteSpace(Request.Form["ReleaseDate"]))
            {
                movie.Slug = UrlEncoder.IsSlugAvailable(_context, "filmitem", Request.Form["Name"]);
            }
            else
            {
                movie.Slug = UrlEncoder.IsSlugAvailable(_context, "filmitem", Request.Form["Name"], DateTime.Parse(Request.Form["ReleaseDate"]).Year);
            }

            _context.Movies.Add(movie);
            FilmItemMethods.AddMediaEntry(_context, movie);
            _context.SaveChanges();

            var images = HttpContext.Request.Form.Files;

            if (images.Count > 0)
            {
                Images.ReadImages(_context, _env, images, "filmitem");
            }

            foreach (var genre in Request.Form["Genre"])
            {
                FilmItemMethods.SaveFilmItemGenres(_context, movie, genre);
            }

            TempData["message"] = $"{movie.Name} has been created";

            return(RedirectToAction("Details", new { Slug = movie.Slug }));
        }
Esempio n. 2
0
        public IActionResult Create(Person person)
        {
            var personName = Request.Form["FirstName"] + " " + Request.Form["Surname"];

            //check if slug is available, else with release year
            if (string.IsNullOrWhiteSpace(Request.Form["BirthDate"]))
            {
                person.Slug = UrlEncoder.IsSlugAvailable(_context, "person", personName);
            }
            else
            {
                person.Slug = UrlEncoder.IsSlugAvailable(_context, "person", personName, DateTime.Parse(Request.Form["BirthDate"]).Year);
            }

            _context.Persons.Add(person);
            FilmItemMethods.AddMediaEntry(_context, null, person);
            _context.SaveChanges();

            var images = HttpContext.Request.Form.Files;

            if (images.Count > 0)
            {
                Images.ReadImages(_context, _env, images, "person");
            }

            TempData["message"] = $"{person.FirstName} {person.Surname} has been created";

            return(RedirectToAction("Details", "Person", new { Slug = person.Slug }));
        }
        public ViewResult Details(string Slug)
        {
            var series = _context.Series.Include(sg => sg.FilmItemGenres).ThenInclude(g => g.Genre)
                         .Include(s => s.Seasons).ThenInclude(e => e.Episodes)
                         .Include(mc => mc.FilmItemCredits).ThenInclude(p => p.Person)
                         .Include(m => m.Media)
                         .Include(v => v.Videos)
                         .Include(p => p.Photos)
                         .Include(mr => mr.UserRatings)
                         .Include(r => r.Reviews)
                         .Include(l => l.ListItems).ThenInclude(l => l.List)
                         .FirstOrDefault(s => s.Slug == Slug);

            SeriesDetailsViewModel seriesDetailsViewModel = new SeriesDetailsViewModel
            {
                Series                = series,
                Genres                = series.FilmItemGenres.Select(g => g.Genre.Name).OrderBy(g => g).ToArray(),
                ReleaseYear           = (series.FirstAirDate.HasValue ? series.FirstAirDate.Value.ToString("yyyy") : ""),
                PremiereDate          = (series.FirstAirDate.HasValue ? series.FirstAirDate.Value.ToString("dd MMMM yyyy") : ""),
                TotalRuntime          = FilmItemMethods.CalculateSeriesTotalRuntime(series),
                CommentCount          = series.Reviews.Count,
                ListCount             = series.ListItems.Select(l => l.List).ToList().Count,
                RecentlyAiredEpisodes = FilmItemMethods.GetRecentlyAiredEpisodes(_context, series)
            };

            return(View(seriesDetailsViewModel));
        }
        public IActionResult Create(string Slug, int SeasonNumber, Episode episode)
        {
            var series = _context.Series.Include(s => s.Seasons).ThenInclude(s => s.Episodes).FirstOrDefault(srs => srs.Slug == Slug);
            var season = _context.Seasons.Where(s => s.SeriesId == series.Id).Where(s => s.Season_SeasonNumber == SeasonNumber).FirstOrDefault();

            var updatedSeries = FilmItemMethods.SaveSeriesInfoAfterCreateEpisode(_context, series);
            var updatedSeason = FilmItemMethods.SaveSeasonInfoAfterCreateEpisode(_context, season);

            // Add new Episode
            episode.SeasonId              = season.Id;
            episode.Episode_SeasonNumber  = updatedSeason.Season_SeasonNumber;
            episode.Episode_EpisodeNumber = updatedSeason.Season_EpisodeCount;
            episode.Slug           = Slug;
            episode.Rel_SeriesId   = series.Id;
            episode.Rel_SeriesName = series.Name;
            _context.Episodes.Add(episode);
            FilmItemMethods.AddMediaEntry(_context, episode);

            _context.SaveChanges();

            var images = HttpContext.Request.Form.Files;

            if (images.Count > 0)
            {
                Images.ReadImages(_context, _env, images, "filmitem");
            }

            return(RedirectToAction("Details", "Season", new { SeasonNumber = SeasonNumber }));
        }
Esempio n. 5
0
        public IActionResult Create(string Slug, Season season)
        {
            var series = _context.Series.Include(s => s.Seasons).FirstOrDefault(x => x.Slug == Slug);

            var updatedSeries = FilmItemMethods.SaveSeriesInfoAfterCreateSeason(_context, series);

            // Add New Season
            season.SeriesId            = series.Id;
            season.Season_SeasonNumber = updatedSeries.Series_SeasonCount;
            season.Slug           = Slug;
            season.Rel_SeriesId   = series.Id;
            season.Rel_SeriesName = series.Name;
            _context.Seasons.Add(season);
            FilmItemMethods.AddMediaEntry(_context, season);
            _context.SaveChanges();

            var images = HttpContext.Request.Form.Files;

            if (images.Count > 0)
            {
                Images.ReadImages(_context, _env, images, "filmitem");
            }

            return(RedirectToAction("Details", "Series", new { Slug = Slug }));
        }
Esempio n. 6
0
        public ViewResult Details(string Slug, int SeasonNumber)
        {
            var series = _context.Series.Include(fig => fig.FilmItemGenres).ThenInclude(g => g.Genre).FirstOrDefault(s => s.Slug == Slug);
            var season = _context.Seasons.Include(ep => ep.Episodes)
                         .Include(mr => mr.UserRatings)
                         .Include(r => r.Reviews)
                         .Include(m => m.Media)
                         .Include(v => v.Videos)
                         .Include(p => p.Photos)
                         .Include(l => l.ListItems).ThenInclude(l => l.List)
                         .Where(x => x.Season_SeasonNumber == SeasonNumber)
                         .Where(y => y.SeriesId == series.Id)
                         .FirstOrDefault();

            SeasonDetailsViewModel seasonDetailsViewModel = new SeasonDetailsViewModel
            {
                Season           = season,
                Genres           = series.FilmItemGenres.Select(g => g.Genre.Name).OrderBy(g => g).ToArray(),
                SeasonCount      = series.Series_SeasonCount,
                TotalRuntime     = FilmItemMethods.CalculateSeasonTotalRuntime(season),
                CommentCount     = season.Reviews.Count,
                ListCount        = season.ListItems.Select(l => l.List).ToList().Count,
                FirstEpisodeDate = GetDateTimeFirstEpisode(season)
            };

            return(View(seasonDetailsViewModel));
        }
Esempio n. 7
0
        public IActionResult DeleteListItem(string Slug, string listName, int Id)
        {
            var user     = _userManager.Users.FirstOrDefault(u => u.Slug == Slug);
            var listItem = _context.ListItems.Include(l => l.List).Include(f => f.FilmItem).FirstOrDefault(li => li.Id == Id);

            if (listItem != null && user.Id == _userManager.GetUserId(User))
            {
                FilmItemMethods.RemoveListItem(_context, listItem);
                TempData["message"] = $"Removed {listItem.FilmItem.Name} from '{listItem.List.Name}'";
            }

            return(RedirectToAction("Details", "List", new { listName = listName }));
        }
Esempio n. 8
0
        public IActionResult AddListItem(string Slug, string listName, string id = null)
        {
            var user     = _userManager.Users.FirstOrDefault(u => u.Slug == Slug);
            var list     = _context.Lists.Where(l => l.Slug == listName).Where(u => u.ApplicationUserId == user.Id).FirstOrDefault();
            var filmItem = _context.FilmItem.Where(f => f.Name == Request.Form["FilmItem"].ToString()).FirstOrDefault();

            if (user.Id == _userManager.GetUserId(User))
            {
                FilmItemMethods.SaveListItem(_context, list, filmItem);
                TempData["message"] = $"{filmItem.Name} is added to {list.Name}";
            }

            return(RedirectToAction("Details", "List", new { listName = listName }));
        }
        public IActionResult ListsModal(string Slug, int SeasonNumber, int EpisodeNumber)
        {
            var episode = _context.Episodes.Where(e => e.Slug == Slug).Where(e => e.Episode_SeasonNumber == SeasonNumber).Where(e => e.Episode_EpisodeNumber == EpisodeNumber).FirstOrDefault();
            var lists   = _context.Lists.Include(li => li.ListItems).ThenInclude(m => m.FilmItem).Where(a => a.ApplicationUserId == _userManager.GetUserId(User)).ToList();

            FilmItemListsModalViewModel filmItemListsViewModel = new FilmItemListsModalViewModel
            {
                Lists             = lists,
                FilmItem          = episode.Rel_SeriesName + " - " + episode.Episode_SeasonNumber + "x" + GetEpisodeNumberString(episode) + " \"" + episode.Name + "\"",
                FilmItemId        = episode.Id,
                ListsWithFilmItem = FilmItemMethods.ListHavingFilmItem(lists, episode)
            };

            return(PartialView("_FilmItemListsModalPartial", filmItemListsViewModel));
        }
Esempio n. 10
0
        public IActionResult ListsModal(string Slug)
        {
            var movie = _context.Movies.FirstOrDefault(m => m.Slug == Slug);
            var lists = _context.Lists.Include(li => li.ListItems).ThenInclude(m => m.FilmItem).Where(a => a.ApplicationUserId == _userManager.GetUserId(User)).ToList();

            FilmItemListsModalViewModel filmItemListsViewModel = new FilmItemListsModalViewModel
            {
                Lists             = lists,
                FilmItem          = movie.Name,
                FilmItemId        = movie.Id,
                ListsWithFilmItem = FilmItemMethods.ListHavingFilmItem(lists, movie)
            };

            return(PartialView("_FilmItemListsModalPartial", filmItemListsViewModel));
        }
Esempio n. 11
0
        public IActionResult ListsModal(string Slug, int SeasonNumber)
        {
            var season = _context.Seasons.Where(s => s.Slug == Slug).Where(s => s.Season_SeasonNumber == SeasonNumber).FirstOrDefault();
            var lists  = _context.Lists.Include(li => li.ListItems).ThenInclude(m => m.FilmItem).Where(a => a.ApplicationUserId == _userManager.GetUserId(User)).ToList();

            FilmItemListsModalViewModel filmItemListsViewModel = new FilmItemListsModalViewModel
            {
                Lists             = lists,
                FilmItem          = season.Rel_SeriesName + " - " + season.Name,
                FilmItemId        = season.Id,
                ListsWithFilmItem = FilmItemMethods.ListHavingFilmItem(lists, season)
            };

            return(PartialView("_FilmItemListsModalPartial", filmItemListsViewModel));
        }
Esempio n. 12
0
        public IActionResult Delete(string Slug, int SeasonNumber)
        {
            var series = _context.Series.FirstOrDefault(srs => srs.Slug == Slug);
            var season = _context.Seasons.Include(e => e.Episodes).Where(s => s.SeriesId == series.Id).Where(s => s.Season_SeasonNumber == SeasonNumber).FirstOrDefault();

            if (season != null)
            {
                FilmItemMethods.EditSeriesInfoAfterDeleteSeason(_context, series, season);
                Images.DeleteImagesBelongingToSeason(_context, _env, season);

                _context.Seasons.Remove(season);
                _context.SaveChanges();

                TempData["message"] = $"{series.Name} - {season.Name} was deleted";
            }

            return(RedirectToAction("Details", "Series", new { Slug = Slug }));
        }
        public IActionResult Delete(string Slug, int SeasonNumber, int Id)
        {
            var series  = _context.Series.FirstOrDefault(srs => srs.Slug == Slug);
            var season  = _context.Seasons.Where(s => s.SeriesId == series.Id).Where(s => s.Season_SeasonNumber == SeasonNumber).FirstOrDefault();
            var episode = _context.Episodes.FirstOrDefault(s => s.Id == Id);

            if (episode != null)
            {
                FilmItemMethods.EditSeriesAndSeasonAfterDeleteEpisode(_context, series, season);
                Images.DeleteAssetImage(_context, _env, "filmItem", episode.Id);

                _context.Episodes.Remove(episode);
                _context.SaveChanges();

                TempData["message"] = $"Episode {episode.Episode_EpisodeNumber} - {episode.Name} from {series.Name} - {season.Name} was deleted";
            }

            return(RedirectToAction("Details", "Season", new { Slug = Slug, SeasonNumber = SeasonNumber }));
        }
Esempio n. 14
0
        public IActionResult EditCredit(EditPersonCreditViewModel edc, string Slug, int Id)
        {
            var filmItemCredit = _context.FilmItemCredits.Include(p => p.Person).Include(f => f.FilmItem).FirstOrDefault(fic => fic.Id == Id);
            var character      = Request.Form["Character"].ToString();
            var partType       = int.Parse(Request.Form["PartType"]);

            if (ModelState.IsValid)
            {
                FilmItemMethods.EditFilmItemCredit(_context, filmItemCredit, partType, character);

                TempData["message"] = $"Edited {filmItemCredit.Person.FirstName} {filmItemCredit.Person.Surname} as '{character}'";
                return(RedirectToAction("Details", "Person", new { Slug = Slug }));
            }
            else
            {
                TempData["message"] = $"Something went wrong";
                return(View(filmItemCredit));
            }
        }
Esempio n. 15
0
        public IActionResult AddCredit()
        {
            var filmItem  = _context.FilmItem.FirstOrDefault(f => f.Id == int.Parse(Request.Form["FilmItemId"]));
            var person    = _context.Persons.Where(fn => fn.FirstName == Request.Form["Firstname"]).Where(sn => sn.Surname == Request.Form["Surname"]).FirstOrDefault();
            var character = Request.Form["Character"].ToString();
            var partType  = int.Parse(Request.Form["PartType"]);

            if (filmItem != null && person != null && character != null && (partType >= 1 && partType <= 7))
            {
                FilmItemMethods.SaveFilmItemCredits(_context, filmItem, person, partType, character);
                TempData["message"] = $"You added {person.FirstName} {person.Surname} to {filmItem.Name} as {(PartType) partType}";
            }
            else
            {
                TempData["message"] = $"You made an error filling in the Person or Character";
            }

            return(RedirectToAction("Details", filmItem.Discriminator, new { Slug = filmItem.Slug }));
        }
Esempio n. 16
0
        public IActionResult AddCredit(string Slug, int i = 0)
        {
            var person    = _context.Persons.FirstOrDefault(p => p.Slug == Slug);
            var filmItem  = _context.FilmItem.Where(f => f.Name == Request.Form["Name"]).DefaultIfEmpty().First();
            var character = Request.Form["Character"].ToString();
            var partType  = int.Parse(Request.Form["PartType"]);

            if (filmItem != null && person != null && character != null && (partType >= 1 && partType <= 7))
            {
                //CreditController
                FilmItemMethods.SaveFilmItemCredits(_context, filmItem, person, partType, character);
                TempData["message"] = $"You added {person.FirstName} {person.Surname} to {filmItem.Name} as {(PartType) partType}";
            }
            else
            {
                TempData["message"] = $"You made an error filling in the Film Item or Character";
            }

            return(RedirectToAction("Details", "Person", new { Slug = Slug }));
        }
Esempio n. 17
0
        public IActionResult AddGenreToFilmItem()
        {
            var filmItem      = _context.FilmItem.FirstOrDefault(m => m.Id == int.Parse(Request.Form["FilmItemId"]));
            var currentGenres = _context.FilmItemGenres.Where(m => m.FilmItemId == filmItem.Id).Select(g => g.GenreId).ToList();

            foreach (var newGenre in Request.Form["Genre"])
            {
                if (currentGenres.Contains(int.Parse(newGenre)))
                {
                    continue;
                }
                else
                {
                    FilmItemMethods.SaveFilmItemGenres(_context, filmItem, newGenre);
                }
                TempData["message"] = $"Added new genres to {filmItem.Name}";
            }

            return(RedirectToAction("Details", filmItem.Discriminator, new { Slug = filmItem.Slug }));
        }
        public IActionResult ListsModal(string Slug, int SeasonNumber, int EpisodeNumber, bool check = false)
        {
            var listsChecked = Request.Form["Lists"].ToList();
            var episode      = _context.Episodes.Where(s => s.Slug == Slug).Where(s => s.Episode_SeasonNumber == SeasonNumber).Where(s => s.Episode_EpisodeNumber == EpisodeNumber).FirstOrDefault();
            var lists        = _context.Lists.Include(li => li.ListItems).Where(u => u.ApplicationUserId == _userManager.GetUserId(User)).ToList();

            foreach (var list in lists)
            {
                var itemInList = list.ListItems.Where(m => m.FilmItem == episode).FirstOrDefault();
                if (itemInList != null && !listsChecked.Contains(list.Id.ToString())) //unchecked -> checked
                {
                    FilmItemMethods.RemoveListItem(_context, itemInList);
                }
                else if (itemInList == null && listsChecked.Contains(list.Id.ToString()))   //checked -> unchecked
                {
                    FilmItemMethods.SaveListItem(_context, list, episode);
                }
            }

            return(RedirectToAction("Details", new { Slug = Slug }));
        }