示例#1
0
        public async Task <GetGenreModel> GetGenre(string id)
        {
            GetGenreModel genre = await _context.Genres
                                  .Select(x => new GetGenreModel
            {
                Id     = x.Id,
                Name   = x.Name,
                Movies = (from movie in _context.Movies
                          where movie.GenreId == x.Id
                          select new GetMovieModel
                {
                    Id = movie.Id,
                    Name = movie.Name,
                    Description = movie.Description,
                    Duration = movie.Duration,
                    Year = movie.Year,
                    OverallRating = movie.OverallRating,
                    GenreId = movie.GenreId,
                    DirectorId = movie.DirectorId
                }).ToList()
            })
                                  .AsNoTracking()
                                  .FirstOrDefaultAsync(x => x.Id == Guid.Parse(id));

            if (genre == null)
            {
                throw new EntityException("Genre not found", this.GetType().Name, "GetGenre", "404");
            }
            return(genre);
        }
示例#2
0
        [ValidateAntiForgeryToken] // Prevents XSRF/CSRF attacks
        public async Task <IActionResult> Create(PostGenreModel postGenreModel)
        {
            try
            {
                AuthorizeHelper.Authorize(this.HttpContext, "Editor", this.GetType().Name, "Create", "genre");


                if (ModelState.IsValid)
                {
                    GetGenreModel getGenreModel = await _moviemindAPIService.PostModel <PostGenreModel, GetGenreModel>(postGenreModel, "Genres");

                    if (TempData["controller"] != null && TempData["action"] != null)
                    {
                        return(RedirectToRoute(new { action = TempData["action"], controller = TempData["controller"] }));
                    }

                    return(RedirectToRoute(new { action = "Index", controller = "Genres" }));
                }

                return(View(postGenreModel));
            }
            catch (MovieMindException e)
            {
                return(ErrorHelper.HandleError(e, this.View(postGenreModel)));
            }
        }
        public async Task <ActionResult <GetGenreModel> > PostGenre(PostGenreModel postGenreModel)
        {
            try
            {
                GetGenreModel genre = await _genreRepository.PostGenre(postGenreModel);

                return(CreatedAtAction(nameof(GetGenre), new { id = genre.Id }, genre));
            }
            catch (DatabaseException e)
            {
                return(BadRequest(e.MovieMindError));
            }
        }
示例#4
0
        public async Task <IActionResult> Details(string id)
        {
            try
            {
                AuthorizeHelper.Authorize(this.HttpContext, "Guest", this.GetType().Name, "Details", "genre");

                GetGenreModel getGenreModel = await _moviemindAPIService.GetModel <GetGenreModel>(id, "Genres");

                return(View(getGenreModel));
            }
            catch (MovieMindException e)
            {
                return(ErrorHelper.HandleError(e));
            }
        }
示例#5
0
        [ValidateAntiForgeryToken] // Prevents XSRF/CSRF attacks
        public async Task <IActionResult> Delete(string id, GetGenreModel getGenreModel)
        {
            try
            {
                AuthorizeHelper.Authorize(this.HttpContext, "Editor", this.GetType().Name, "Delete", "genre");

                await _moviemindAPIService.DeleteModel(id, "Genres");

                return(RedirectToRoute(new { action = "Index", controller = "Genres" }));
            }
            catch (MovieMindException e)
            {
                return(ErrorHelper.HandleError(e, this.View(getGenreModel)));
            }
        }
示例#6
0
        public async Task <IActionResult> Edit(string id)
        {
            try
            {
                AuthorizeHelper.Authorize(this.HttpContext, "Editor", this.GetType().Name, "Edit", "genre");

                GetGenreModel getGenreModel = await _moviemindAPIService.GetModel <GetGenreModel>(id, "Genres");

                PutGenreModel putGenreModel = new PutGenreModel
                {
                    Name = getGenreModel.Name
                };

                return(View(putGenreModel));
            }
            catch (MovieMindException e)
            {
                return(ErrorHelper.HandleError(e));
            }
        }