예제 #1
0
        public IActionResult Edit(GenreViewModel genre)
        {
            if (!ModelState.IsValid)
            {
                return(View());
            }

            var genreModel = _genreService.GetGenreById(genre.Id);

            genreModel.Name = genre.Name;
            genreModel.Id   = genre.Id;

            _genreService.AddGenreTranslate(genre.NameRu, "ru", genreModel.Id);

            _genreService.EditGenre(genreModel);

            return(RedirectToAction(nameof(Index)));
        }
예제 #2
0
        public IActionResult Insert([FromForm] GenreViewModel genre)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var genreId  = Guid.NewGuid();
            var genreNew = new Genre()
            {
                Name = genre.Name, Id = genreId
            };

            if (genre.ParentGenre != null)
            {
                var genreModel = _genreService.GetGenreByName(genre.ParentGenre);
                genreNew.ParentGenreId = genreModel.Id;
            }

            _genreService.CreateGenre(genreNew);
            _genreService.AddGenreTranslate(genre.NameRu, "ru", genreId);

            return(Ok(genreNew));
        }