Exemple #1
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));
            }
        }
Exemple #3
0
        public async Task <GetGenreModel> PostGenre(PostGenreModel postGenreModel)
        {
            try
            {
                EntityEntry <Genre> result = await _context.Genres.AddAsync(new Genre
                {
                    Name = postGenreModel.Name
                });

                await _context.SaveChangesAsync();

                return(await GetGenre(result.Entity.Id.ToString()));
            }
            catch (MovieMindException)
            {
                throw;
            }
            catch (Exception e)
            {
                throw new DatabaseException(e.InnerException.Message, this.GetType().Name, "PostGenre", "400");
            }
        }