Esempio n. 1
0
        public void Delete(int id)
        {
            Moviegoer moviegoerToDelete = _repo.Moviegoer.GetMoviegoerById(id);

            _repo.Moviegoer.Delete(moviegoerToDelete);
            _repo.Save();
        }
Esempio n. 2
0
        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));
        }
Esempio n. 3
0
        // 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));
        }
Esempio n. 4
0
        // 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));
        }
Esempio n. 5
0
        // 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);
            }
        }
Esempio n. 7
0
        // 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));
        }
Esempio n. 8
0
        private async Task <Vote> CreateNewVote(string userId)
        {
            Moviegoer moviegoer = await MoviegoerAPI.GetByUserId(userId);

            Vote vote = new Vote()
            {
                MoviegoerId = moviegoer.Id,
                Moviegoer   = moviegoer
            };

            return(vote);
        }
Esempio n. 9
0
 public ActionResult CreateMoviegoer(Moviegoer moviegoer)
 {
     try
     {
         MoviegoerAPI.Create(moviegoer);
         return(RedirectToAction(nameof(IndexWithMoviegoerParameter), moviegoer));
     }
     catch
     {
         return(View());
     }
 }
Esempio n. 10
0
        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);
        }
Esempio n. 11
0
 public ActionResult IndexWithMoviegoerParameter(Moviegoer moviegoer)
 {
     return(View("index", moviegoer));
 }
Esempio n. 12
0
 public ActionResult Edit(int id, Moviegoer moviegoer)
 {
     MoviegoerAPI.Update(moviegoer);
     return(RedirectToAction(nameof(Details)));
 }
Esempio n. 13
0
 public void Put(int id, [FromBody] Moviegoer moviegoer)
 {
     _repo.Moviegoer.Update(moviegoer);
     _repo.Save();
 }
Esempio n. 14
0
 public void Post([FromBody] Moviegoer moviegoer)
 {
     _repo.Moviegoer.Create(moviegoer);
     _repo.Save();
 }