public void Delete(int id) { Moviegoer moviegoerToDelete = _repo.Moviegoer.GetMoviegoerById(id); _repo.Moviegoer.Delete(moviegoerToDelete); _repo.Save(); }
public async Task <ActionResult> DisplayNominations(string year, string category) { if (!User.Identity.IsAuthenticated) { return(RedirectToAction("DisplayNominations", "Home", new YearCategoryModel(year, category))); } string userId = this.User.FindFirstValue(ClaimTypes.NameIdentifier); Moviegoer moviegoer = await MoviegoerAPI.GetByUserId(userId); List <Vote> myVotes = await VoteAPI.GetByIdentityUserIdYearOfNominationAndCategory(userId, year, category); bool hasVotedThisYear = myVotes.Where(v => v.Date.Year == DateTime.Now.Year).FirstOrDefault() != null; if (!hasVotedThisYear) { return(RedirectToAction(nameof(VoteOnNomination), new YearCategoryModel(year, category))); } NominationViewModel nominationViewModel = await CreateNominationViewModel(year, category); nominationViewModel.JsonVotes = JsonDataBuilder.CreateJsonVoteCollection(nominationViewModel); nominationViewModel.JsonNomineeNames = JsonDataBuilder.CreateJsonStringFromStringList(nominationViewModel.Nominations.Select(n => n.Nominee).ToList()); nominationViewModel.MyVotes = await VoteAPI.GetByIdentityUserIdYearOfNominationAndCategory(userId, year, category); nominationViewModel.AllYearCategoryCombinations = await NominationAPI.GetAllYearCategoryCombinations(); return(View(nominationViewModel)); }
// GET: Cinephile/Edit/5 public async Task <ActionResult> Edit() { string userId = this.User.FindFirstValue(ClaimTypes.NameIdentifier); Moviegoer moviegoer = await MoviegoerAPI.GetByUserId(userId); return(View(moviegoer)); }
// GET: Admin/Details/5 public async Task <ActionResult> MoviegoerDetails(int id) { List <Moviegoer> moviegoers = await MoviegoerAPI.GetAll(); Moviegoer moviegoer = moviegoers.Where(m => m.Id == id).FirstOrDefault(); return(View(moviegoer)); }
// GET: Cinephile/Create public ActionResult CreateMoviegoer() { Moviegoer moviegoer = new Moviegoer() { IdentityUserId = this.User.FindFirstValue(ClaimTypes.NameIdentifier) }; return(View(moviegoer)); }
public static async void Update(Moviegoer moviegoer) { string jsonMoviegoer = JsonConvert.SerializeObject(moviegoer); using (HttpClient client = new HttpClient()) { StringContent moviegoerHttp = new StringContent(jsonMoviegoer, UnicodeEncoding.UTF8, "application/json"); HttpResponseMessage response = await client.PutAsync("https://localhost:44366/api/Moviegoers/" + moviegoer.Id, moviegoerHttp); } }
// GET: Cinephile public async Task <ActionResult> Index() { string userId = this.User.FindFirstValue(ClaimTypes.NameIdentifier); Moviegoer moviegoer = await MoviegoerAPI.GetByUserId(userId); if (moviegoer == null) { return(RedirectToAction(nameof(CreateMoviegoer))); } return(View(moviegoer)); }
private async Task <Vote> CreateNewVote(string userId) { Moviegoer moviegoer = await MoviegoerAPI.GetByUserId(userId); Vote vote = new Vote() { MoviegoerId = moviegoer.Id, Moviegoer = moviegoer }; return(vote); }
public ActionResult CreateMoviegoer(Moviegoer moviegoer) { try { MoviegoerAPI.Create(moviegoer); return(RedirectToAction(nameof(IndexWithMoviegoerParameter), moviegoer)); } catch { return(View()); } }
public static async Task <List <Vote> > GetByIdentityUserIdYearOfNominationAndCategory(string identityUserId, string yearOfNomination, string category) { List <Vote> votes = await GetAll(); Moviegoer moviegoer = await MoviegoerAPI.GetByUserId(identityUserId); votes = votes.Where(v => v.MoviegoerId == moviegoer.Id).ToList(); List <Nomination> nominations = await NominationAPI.GetNominationsByYearAndCategoryIncludeMovie(yearOfNomination, category); votes = votes.Where(v => nominations.Select(n => n.Id).Contains(v.NominationId)).ToList(); foreach (Vote vote in votes) { vote.Nomination = await NominationAPI.GetById(vote.NominationId); } return(votes); }
public ActionResult IndexWithMoviegoerParameter(Moviegoer moviegoer) { return(View("index", moviegoer)); }
public ActionResult Edit(int id, Moviegoer moviegoer) { MoviegoerAPI.Update(moviegoer); return(RedirectToAction(nameof(Details))); }
public void Put(int id, [FromBody] Moviegoer moviegoer) { _repo.Moviegoer.Update(moviegoer); _repo.Save(); }
public void Post([FromBody] Moviegoer moviegoer) { _repo.Moviegoer.Create(moviegoer); _repo.Save(); }