public IActionResult OnGet(int?id)
        {
            var claimsIdentity = (ClaimsIdentity)User.Identity;
            var claim          = claimsIdentity.FindFirst(ClaimTypes.NameIdentifier);
            var isAdmin        = User.IsInRole(MovieCollections.Utility.SD.AdminRole);

            MovieItemObj = new MovieItemVM
            {
                MovieItem       = new Models.MovieItem(),
                MovieList       = _unitOfWork.Movie.GetMovieListForDropDown(),
                CollectionsList = isAdmin ? _unitOfWork.Collections.GetCollectionsListForDropDown() : _unitOfWork.Collections.GetCollectionsListForDropDown(claim.Value)
            };

            if (id != null)
            {
                if (claim != null)
                {
                    Models.MovieItem movieItem = _unitOfWork.MovieItem.GetFirstOrDefault(c => c.UserId == claim.Value);
                    MovieItemObj.MovieItem = movieItem;

                    //MovieItemObj.MovieItem = _unitOfWork.MovieItem.GetFirstOrDefault(u => u.Id == id);

                    if (MovieItemObj == null)
                    {
                        return(NotFound());
                    }
                }
            }

            return(Page()); //refresh page call onGet again without id
        }
Exemplo n.º 2
0
 public IActionResult Post([FromBody] MovieItemVM movie)
 {
     try
     {
         if (movie == null)
         {
             return(NotFound("no movie found"));
         }
         else
         {
             Movie newMovie = new Movie()
             {
                 Description = movie.Description,
                 Director    = db.Person.FirstOrDefault(p => p.LastName.Equals("Diesel")),
                 Year        = movie.Year,
                 Title       = movie.Title,
                 Stars       = movie.Rating,
                 Genre       = db.Genre.FirstOrDefault(g => g.GenreId == 1)
             };
             db.Movie.Add(newMovie);
             db.SaveChanges();
             //return Created(Url.Link("GetMovies"), new {id = newMovie.MovieId}), newMovie);
             return(Ok("movie added"));
         }
     }
     catch (Exception e)
     {
         return(BadRequest(e));
     }
 }
Exemplo n.º 3
0
        public IActionResult AddMovie(MovieItemVM movieItem)
        {
            if (ModelState.IsValid)
            {
                string stringData  = JsonConvert.SerializeObject(movieItem);
                var    contentData = new StringContent(stringData, System.Text.Encoding.UTF8, "application/json");


                HttpResponseMessage response = client.PostAsync("/api/movies", contentData).Result;
                var content = Content(response.Content.ReadAsStringAsync().Result.ToString());

                //Call api with productvm
                return(RedirectToAction("Index"));
            }
            return(View(movieItem));
        }