// Decreases the episode number for this specific showcard public IActionResult MinusEpisode(int showCardID) { int userID = GetUserID(); if (userID == 0) { return(RedirectToAction("Login", "User")); } string message = null; ShowCard show = new ShowCard(); using (WeWatchContext context = new WeWatchContext()) { // Get the show that the showcard is referencing show = context.ShowCard.Include(x => x.Show).Where(x => x.ShowCardID == showCardID).Single(); // Get the show season attached to that card ShowSeason currentSeason = context.ShowSeason.Where(x => x.ShowID == show.ShowID && x.ShowSeasonID == show.CurrentSeason).Single(); // Check if we are at the minimum episode of any season if (show.CurrentEpisode == 1) { // Check to see if there is a lower season recorded for this show ShowSeason pastSeason = context.ShowSeason.Include(x => x.Show).Where(x => x.ShowID == show.ShowID && x.IndividualSeason < currentSeason.IndividualSeason).OrderBy(x => x.IndividualSeason).FirstOrDefault(); // Prompt user to add a season to the list if there is no lower season if (pastSeason == null) { message = "Sorry you no season to go back to. Would you like to add a season to the list?"; } // Roll back to the next lowest season, max episode else { show.CurrentEpisode = pastSeason.SeasonEpisodes; show.CurrentSeason = pastSeason.ShowSeasonID; message = "You went back a SEASON"; } } // Can simply minus one episode from the episode number else { show.CurrentEpisode--; message = "Went back an EPISODE"; } context.SaveChanges(); } TempData["message"] = message; return(RedirectToAction("ByShow", new { showID = show.ShowID })); }
private void SetActiveSeasonsListBoxItem() { showsListBox.SelectedIndex = 0; if ((ShowSeason)seasonsListBox.SelectedItem != selectedSeason) { selectedSeason = new ShowSeason(); selectedSeason = (ShowSeason)seasonsListBox.SelectedItem; } seasonsListBox.SetSelected(0, true); }
//Delete show function public void Delete(string Id) { ShowSeason showSeasonToDelete = showSeason.Find(p => p.Id == Id); if (showSeasonToDelete != null) { showSeason.Remove(showSeasonToDelete); } else { throw new Exception("Show no found"); } }
private void SeasonsListBox_SelectedIndexChanged(object sender, EventArgs e) { if (seasons.Count == 0) { showSeasonEpisodesButton.Enabled = false; return; } selectedSeason = (ShowSeason)seasonsListBox.SelectedItem; addRemoveFavoritesButton.Enabled = true; showSeasonEpisodesButton.Enabled = true; }
//Find function public ShowSeason Find(string Id) { ShowSeason showSeasonToFind = showSeason.Find(p => p.Id == Id); if (showSeasonToFind != null) { return(showSeasonToFind); } else { throw new Exception("Show Season not found"); } }
// Delete show season function public ActionResult Delete(string Id) { ShowSeason showSeasonToDelete = context.Find(Id); if (showSeasonToDelete == null) { return(HttpNotFound()); } else { return(View(showSeasonToDelete)); } }
//Update function public void Update(ShowSeason s) { ShowSeason showSeasonToUpdate = showSeason.Find(p => p.Id == s.Id); if (showSeasonToUpdate != null) { showSeasonToUpdate = s; } else { throw new Exception("Show Season not found"); } }
public EpisodesForm(User userModel, ShowSeason seasonModel, Show showModel) { InitializeComponent(); user = userModel; show = showModel; season = seasonModel; this.Text = $"{this.Text} - {show.Title} - Episodes - Season {season.Season}"; this.AcceptButton = episodeDetailsButton; api = new API(user); }
// Edit show season function public ActionResult Edit(string Id) { ShowSeason showseason = context.Find(Id); if (showseason == null) { return(HttpNotFound()); } else { return(View(showseason)); } }
public ActionResult Create(ShowSeason showseason) { if (!ModelState.IsValid) { return(View(showseason)); } else { context.Insert(showseason); context.Commit(); return(RedirectToAction("Index")); } }
public IActionResult AddSeason(int showID, string newSeason, string newEpisodes) { if (!IsLoggedIn()) { return RedirectToAction("Login", "User"); } string message = null; using (WeWatchContext context = new WeWatchContext()) { Show show = context.Show.Where(x => x.ShowID == showID).SingleOrDefault(); if (!int.TryParse(newSeason, out int parsedNewSeason)) { message = "Seasons must be positive valid numbers."; } else if (parsedNewSeason < 1 || parsedNewSeason > 50) { message = "Season must be between 1 and 50."; } else if (!int.TryParse(newEpisodes, out int parsedNewEpisodes)) { message = "Episodes must be positive valid numbers."; } else if (parsedNewEpisodes < 1 || parsedNewEpisodes > 50) { message = "Episodes must be between 1 and 50."; } else if (context.ShowSeason.Where(x => x.ShowID == showID).Where(x => x.IndividualSeason == parsedNewSeason).SingleOrDefault() != null) { message = $"Season already exists in {show.Title}"; } else { ShowSeason showSeason = new ShowSeason() { ShowID = showID, IndividualSeason = parsedNewSeason, SeasonEpisodes = parsedNewEpisodes }; context.ShowSeason.Add(showSeason); context.SaveChanges(); message = $"Successfully added season { parsedNewSeason } to {show.Title}"; } } TempData["message"] = message; return Redirect("ManageShows"); }
public ActionResult ConfirmDelete(string Id) { ShowSeason showSeasonToDelete = context.Find(Id); if (showSeasonToDelete == null) { return(HttpNotFound()); } else { context.Delete(Id); context.Commit(); return(RedirectToAction("Index")); } }
public IActionResult DeleteSeason(int deleteSeason) { if (!IsLoggedIn()) { return RedirectToAction("Login", "User"); } string messages; using (WeWatchContext context = new WeWatchContext()) { string tempTitle; // Make sure a value was passed for the seasonID if (deleteSeason == 0) { messages = "Cannot delete unknown program. Please refresh and try again."; } else { // Check to see if the passed value matches a seasonID ShowSeason season = context.ShowSeason.Where(x => x.ShowSeasonID == deleteSeason).SingleOrDefault(); if (season == null) { messages = "Cannot find program. Please refresh and try again."; } // Check that if there is a show card with that season referenced as watching else if (context.ShowCard.Where(x => x.CurrentSeason == season.ShowSeasonID).Count() > 0) { messages = "Cannot delete a season with a Show Card reference."; } // We can delete the season else { tempTitle = context.Show.Where(x => x.ShowID == season.ShowID).Select(y => y.Title).SingleOrDefault().ToString(); context.ShowSeason.Remove(season); context.SaveChanges(); messages = $"Successfully deleted Season number {season.IndividualSeason} from {tempTitle}"; } } } // Return messages TempData["message"] = messages; return Redirect("ManageShows"); }
public IActionResult AddShow(string title, int indSeason, int episodes) { if (!IsLoggedIn()) { return RedirectToAction("Login", "User"); } string messages; using (WeWatchContext context = new WeWatchContext()) { if (title.Length > 50) { messages = ("Program name cannot be greater than 50 characters."); } else if (context.Show.Where(x => x.Title.ToUpper() == title.ToUpper().Trim()).Count() > 0) { messages = ($"{title} already exists."); } else if (indSeason < 1 || indSeason > 50) { messages = ("Seasons must be between 1 and 50."); } else if (episodes < 1) { messages = ("Episodes must be between 1 and 50."); } else { Show newShow = new Show() { Title = title.Trim() }; context.Show.Add(newShow); context.SaveChanges(); int showID = context.Show.Where(x => x.Title == title.Trim()).Single().ShowID; ShowSeason newSeason = new ShowSeason() { ShowID = showID, IndividualSeason = indSeason, SeasonEpisodes = episodes }; context.ShowSeason.Add(newSeason); context.SaveChanges(); messages = ($"Successfully added {newShow.Title}"); } } TempData["message"] = messages; return Redirect("ManageShows"); }
// Increases the Episode number on a specific showcard public IActionResult AddEpisode(int showCardID) { int userID = GetUserID(); if (userID == 0) { return(RedirectToAction("Login", "User")); } string message = null; ShowCard show = new ShowCard(); using (WeWatchContext context = new WeWatchContext()) { show = context.ShowCard.Include(x => x.Show).Where(x => x.ShowCardID == showCardID).Single(); ShowSeason currentSeason = context.ShowSeason.Where(x => x.ShowID == show.ShowID && x.ShowSeasonID == show.CurrentSeason).Single(); if (show.CurrentEpisode >= currentSeason.SeasonEpisodes) { ShowSeason nextSeason = context.ShowSeason.Include(x => x.Show).Where(x => x.ShowID == show.ShowID && x.IndividualSeason > currentSeason.IndividualSeason).OrderBy(x => x.IndividualSeason).FirstOrDefault(); if (nextSeason == null) { message = "Sorry you have reached the end. Would you like to add another season?"; } else { show.CurrentEpisode = 1; show.CurrentSeason = nextSeason.ShowSeasonID; message = "You started a new Season!"; } } else { show.CurrentEpisode++; message = "Next episode"; } context.SaveChanges(); } TempData["message"] = message; return(RedirectToAction("ByShow", new { showID = show.ShowID })); }
private void AddRemoveFavoritesButton_Click(object sender, EventArgs e) { FavoriteShow fs = new FavoriteShow() { ShowId = selectedShow.Id, Show = selectedShow, UserId = user.Id, User = user }; FavoriteShow favoriteShow = GlobalConfig.Connection.FindFavoriteShowByIds(fs); if (favoriteShow == null) { GlobalConfig.Connection.AddFavoriteShow(fs); addRemoveFavoritesButton.Text = RemoveFromFavoritesText; shows.Add(selectedShow); } else { GlobalConfig.Connection.RemoveFavoriteShow(favoriteShow); addRemoveFavoritesButton.Text = AddToFavoritesText; shows.Remove(selectedShow); seasonsListBox.Items.Clear(); selectedSeason = null; selectedShow = null; } if (CurrentEndpointSlug == FavoritesEndpointSlug) { PopulateShowsListBox(); } }
public ActionResult Edit(ShowSeason showseason, string Id) { ShowSeason showSeasonToEdit = context.Find(Id); if (showSeasonToEdit == null) { return(HttpNotFound()); } else { if (!ModelState.IsValid) { return(View(showseason)); } showSeasonToEdit.ShowSeasonAired = showseason.ShowSeasonAired; context.Commit(); return(RedirectToAction("Index")); } }
// Create shows season function public ActionResult Create() { ShowSeason showSeason = new ShowSeason(); return(View(showSeason)); }
public IActionResult EditSeason(int editSeason, string season, string episodes) { if (!IsLoggedIn()) { return RedirectToAction("Login", "User"); } using WeWatchContext context = new WeWatchContext(); string message; int tempSeason; int tempEpisodes; if (editSeason == 0) { message = "Cannot edit unknown season. Please refresh and try again"; } else { ShowSeason targetSeason = context.ShowSeason.Where(x => x.ShowSeasonID == editSeason).SingleOrDefault(); if (season == null) { message = "Cannot find that season. Please refresh and try again"; } else { Show show = context.Show.Where(x => x.ShowID == targetSeason.ShowID).SingleOrDefault(); if (show == null) { message = "Cannot find that program. Please refresh and try again."; } else { if (!int.TryParse(season, out int parsedNewSeason)) { message = "Seasons must be positive valid numbers"; } else if (parsedNewSeason < 1 || parsedNewSeason > 50) { message = "Season must be between 1 and 50"; } else if (!int.TryParse(episodes, out int parsedNewEpisodes)) { message = "Episodes must be positive valid numbers"; } else if (parsedNewEpisodes < 1 || parsedNewEpisodes > 50) { message = "Episodes must be between 1 and 50"; } // To avoid giving a false error when applying the no season duplicate constraint if the user is only editting the episodes, we must first check that the new season and the season that they are attempting to submit are not the same. If they are not we can continue to check if there is a duplicate. else if (parsedNewSeason != targetSeason.IndividualSeason && context.ShowSeason.Where(x => x.ShowID == targetSeason.ShowID).Where(x => x.IndividualSeason == parsedNewSeason).SingleOrDefault() != null) { message = $"Season already exists in {show.Title}"; } else if (parsedNewSeason == targetSeason.IndividualSeason && parsedNewEpisodes == targetSeason.SeasonEpisodes) { message = $"No Changes were detected for {show.Title} - Season {targetSeason.IndividualSeason}."; } else if (context.ShowCard.Where(x => x.CurrentSeason == targetSeason.ShowSeasonID).Count() > 0) { message = "Cannot edit a season with a Show Card reference."; } else { tempSeason = targetSeason.IndividualSeason; tempEpisodes = targetSeason.SeasonEpisodes; targetSeason.IndividualSeason = parsedNewSeason; targetSeason.SeasonEpisodes = parsedNewEpisodes; context.SaveChanges(); message = $"Successfully changed {show.Title} from season {tempSeason} having {tempEpisodes} episodes to season {parsedNewSeason} having {parsedNewEpisodes} episodes."; } } } } TempData["message"] = message; return Redirect("ManageShows"); }
//Insert function public void Insert(ShowSeason s) { showSeason.Add(s); }
// Ensure all the neccessary information to create a show card is received public IActionResult CreateCard(int showID, int watcherID, int seasonID, int episode) { string message = TempData["message"]?.ToString(); int userID = GetUserID(); if (userID == 0) { return(RedirectToAction("Login", "User")); } using WeWatchContext context = new WeWatchContext(); Show selectedShow = new Show(); ShowSeason selectedSeason = new ShowSeason(); Watcher selectedWatcher = new Watcher(); List <ShowSeason> seasons = new List <ShowSeason>(); DisplayCard card = new DisplayCard(); // A show and a watcher must be selected before seasons can be determined if (showID != 0 && watcherID != 0) { card = new DisplayCard(showID, watcherID); // Check to see if this user already has a card with this watcher and this show if (context.ShowCard.Where(x => x.ShowID == card.ShowID && x.WatcherID == card.WatcherID && x.UserID == userID).Count() != 0) { message = $"You are already watching {card.ShowTitle} with {card.WatcherName}"; } // Populate the seasons for this show else { seasons = context.ShowSeason.Where(x => x.ShowID == showID).OrderBy(x => x.IndividualSeason).ToList(); // Populate episodes if season has been selected if (seasonID != 0) { card.SeasonID = seasonID; selectedSeason = context.ShowSeason.Where(x => x.ShowSeasonID == seasonID).Single(); card.CurrentEpisode = episode; } } } // If we were passed a ShowCardID from another action, create a displayCard if (TempData["showCardID"] != null) { int showCardID = int.Parse(TempData["showCardID"].ToString()); ShowCard show = context.ShowCard.Where(x => x.ShowCardID == showCardID).Single(); card = new DisplayCard(show.ShowID, show.WatcherID) { SeasonID = show.CurrentSeason, CurrentEpisode = show.CurrentEpisode }; } ViewBag.Card = card; List <Show> allShows = context.Show.OrderBy(x => x.Title).ToList(); List <Watcher> allWatchers = context.Watcher.OrderBy(x => x.Name).ToList(); ViewBag.Message = message; ViewBag.AllShows = allShows; ViewBag.AllWatchers = allWatchers; ViewBag.Seasons = seasons; return(View()); }