示例#1
0
        public ActionResult Edit(string genre, string newgenre)
        {
            var genres = _repository.GetAll();

            if (!genres.Contains(genre))
            {
                return(NotFound());
            }

            if (genres.Contains(newgenre))
            {
                return(RedirectToAction("index"));
            }

            if (string.IsNullOrWhiteSpace(newgenre))
            {
                ModelState.AddModelError("key", "New genre value cannot be empty.");

                return(View(genre));
            }

            _repository.Edit(genre, newgenre);

            return(RedirectToAction("index"));
        }
示例#2
0
 public void Edit(Genre genre)
 {
     try
     {
         _genreRepository.Edit(genre);
         _logger.LogInformation(LoggerMessageDisplay.GenreEdited);
     }
     catch (Exception ex)
     {
         _logger.LogInformation(LoggerMessageDisplay.GenreEditedError, ex);
     }
 }
示例#3
0
        public IActionResult Edit(Genre genre)
        {
            if (ModelState.IsValid)
            {
                var newGenre = new Genre()
                {
                    GenreId   = genre.GenreId,
                    GenreName = genre.GenreName
                };


                if (genreRepository.Edit(newGenre) != null)
                {
                    return(RedirectToAction("Index"));
                }
            }
            return(View());
        }
示例#4
0
        public IActionResult Edit(int id, Genre genre)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    _genreRepository.Edit(genre);
                    _logger.LogInformation(LoggerMessageDisplay.GenreEdited);
                }
                catch (Exception ex)
                {
                    _logger.LogError(LoggerMessageDisplay.GenreEditErrorModelStateInvalid + "---> " + ex);
                    return(View("Error"));
                }
                return(RedirectToAction(nameof(Index)));
            }

            return(View(genre));
        }
        private void AddGenre(Comic comic, IGenreRepository genreRepository, string genreStr)
        {
            if (string.IsNullOrEmpty(genreStr)) return;

            string[] genres = genreStr.Split(',');

            foreach (string genre in genres)
            {
                string genreTrim = genre.Trim();

                Genre genreDb = genreRepository.Find(g => g.GenreName.Equals(genreTrim)).FirstOrDefault();

                if (genreDb == null)
                {
                    genreDb = new Genre
                    {
                        GenreName = genreTrim,
                        Comics = new List<Comic>()
                    };

                    genreDb.Comics.Add(comic);
                    genreRepository.Add(genreDb);
                }
                else
                {
                    if (genreDb.Comics == null) genreDb.Comics = new List<Comic>();
                    if (genreDb.Comics.Any(c => c.ComicUrl.Equals(comic.ComicUrl))) continue;

                    genreDb.Comics.Add(comic);
                    genreRepository.Edit(genreDb);
                }

                if (comic.Genres == null) comic.Genres = new List<Genre>();
                if (!comic.Genres.Any(g => g.GenreName.Equals(genreTrim)))
                {
                    comic.Genres.Add(genreDb);
                }

                genreRepository.Save();
            }
        }