public async Task <IActionResult> Edit(EditSeriesInputModel model)
        {
            if (!this.ModelState.IsValid)
            {
                model.RetrievedGenres = this.genreRetrievalService.GetAllAsKeyValuePairs();
                return(this.View(model));
            }

            var serviceModel = new EditSeriesServiceModel
            {
                Id          = model.Id,
                Title       = model.Title,
                Ongoing     = model.Ongoing,
                Description = model.Description,
                CoverImage  = await model.CoverImage.GetBytes(),
                CoverPath   = model.CoverPath,
                Genres      = model.Genres,
            };

            var id = this.seriesEditingService.EditSeries(serviceModel);

            if (id == null)
            {
                return(this.NotFound());
            }

            this.cache.RemoveSeriesDetails(id.Value);
            this.cache.RemoveAllArcDetails(this.cacheKeyHolder);
            this.cache.RemoveAllVolumeDetails(this.cacheKeyHolder);
            this.cache.RemoveAllIssueDetails(this.cacheKeyHolder);

            return(this.Redirect($"/Series/{id.Value}"));
        }
Esempio n. 2
0
        public int?EditSeries(EditSeriesServiceModel model)
        {
            var selectedGenres = new List <Genre>();

            if (model.Genres != null)
            {
                selectedGenres = this.dbContext.Genres
                                 .ToList()
                                 .Where(g => model.Genres.Any(x => x == g.Id))
                                 .ToList();
            }

            var currentSeries = this.dbContext.Series
                                .Include(s => s.Genres)
                                .Where(s => s.Id == model.Id)
                                .FirstOrDefault();

            if (currentSeries == null)
            {
                return(null);
            }

            currentSeries.Title       = model.Title;
            currentSeries.Description = model.Description;
            currentSeries.Ongoing     = model.Ongoing;
            currentSeries.Genres      = selectedGenres;

            // else if -> Only updates thumbnail if data is passed.
            if (model.CoverImage != null)
            {
                var uniqueFileName = this.fileUploadService.GetUploadedFileName(model.CoverImage, model.Title);

                // Delete old cover image and replace it with the new one.
                this.fileUploadService.DeleteCover(currentSeries.CoverPath);
                currentSeries.CoverPath = uniqueFileName;
            }
            else if (model.CoverPath != null)
            {
                currentSeries.CoverPath = model.CoverPath;
            }

            this.dbContext.Update(currentSeries);
            this.dbContext.SaveChanges();

            return(currentSeries.Id);
        }