Ejemplo n.º 1
0
        public override async Task <GetSeriesByIdResponse> GetSeriesById(SeriesId request, ServerCallContext context)
        {
            try
            {
                var series = await _series.GetSeriesById(request.Id);

                if (series is null)
                {
                    throw new Exception("SeriesRep - GetSeriesById");
                }
                var seriesFull = _mapper.Map <Series2, SeriesFull>(series);
                return(new GetSeriesByIdResponse()
                {
                    Series = seriesFull, Signal = true
                });
            }
            catch (Exception e)
            {
                _logger.LogError(e, "ERROR");
                return(new GetSeriesByIdResponse()
                {
                    Series = null, Signal = false
                });
            }
        }
Ejemplo n.º 2
0
        public override async Task <SeriesModel> ExecuteAsync(GetSeriesByIdQuery command, CancellationToken cancellationToken = new CancellationToken())
        {
            var series = await _seriesRepository.GetSeriesById(command.LibraryId, command.SeriesId, cancellationToken);

            if (series != null && series.ImageId.HasValue)
            {
                series.ImageUrl = await ImageHelper.TryConvertToPublicFile(series.ImageId.Value, _fileRepository, cancellationToken);
            }

            return(series);
        }
Ejemplo n.º 3
0
        public override async Task <AddBookRequest> HandleAsync(AddBookRequest command, CancellationToken cancellationToken = new CancellationToken())
        {
            IEnumerable <AuthorModel> authors = null;

            if (command.Book.Authors != null && command.Book.Authors.Any())
            {
                authors = await _authorRepository.GetAuthorByIds(command.LibraryId, command.Book.Authors.Select(a => a.Id), cancellationToken);

                if (authors.Count() != command.Book.Authors.Count())
                {
                    throw new BadRequestException();
                }
            }

            if (authors == null || authors.FirstOrDefault() == null)
            {
                throw new BadRequestException();
            }

            SeriesModel series = null;

            if (command.Book.SeriesId.HasValue)
            {
                series = await _seriesRepository.GetSeriesById(command.LibraryId, command.Book.SeriesId.Value, cancellationToken);

                if (series == null)
                {
                    throw new BadRequestException();
                }
            }

            IEnumerable <CategoryModel> categories = null;

            if (command.Book.Categories != null && command.Book.Categories.Any())
            {
                categories = await _categoryRepository.GetCategoriesByIds(command.LibraryId, command.Book.Categories.Select(c => c.Id), cancellationToken);

                if (categories.Count() != command.Book.Categories.Count())
                {
                    throw new BadRequestException();
                }
            }

            command.Result = await _bookRepository.AddBook(command.LibraryId, command.Book, command.AccountId, cancellationToken);

            command.Result.SeriesName = series?.Name;
            command.Result.Authors    = authors?.ToList();
            command.Result.Categories = categories?.ToList();

            return(await base.HandleAsync(command, cancellationToken));
        }
Ejemplo n.º 4
0
        public override async Task <UpdateSeriesImageRequest> HandleAsync(UpdateSeriesImageRequest command, CancellationToken cancellationToken = new CancellationToken())
        {
            var series = await _seriesRepository.GetSeriesById(command.LibraryId, command.SeriesId, cancellationToken);

            if (series == null)
            {
                throw new NotFoundException();
            }

            if (series.ImageId.HasValue)
            {
                command.Image.Id = series.ImageId.Value;

                var existingImage = await _fileRepository.GetFileById(series.ImageId.Value, cancellationToken);

                if (existingImage != null && !string.IsNullOrWhiteSpace(existingImage.FilePath))
                {
                    await _fileStorage.TryDeleteImage(existingImage.FilePath, cancellationToken);
                }

                var url = await AddImageToFileStore(series.Id, command.Image.FileName, command.Image.Contents, command.Image.MimeType, cancellationToken);

                command.Image.FilePath = url;
                command.Image.IsPublic = true;
                await _fileRepository.UpdateFile(command.Image, cancellationToken);

                command.Result.File    = command.Image;
                command.Result.File.Id = series.ImageId.Value;
            }
            else
            {
                command.Image.Id = default(int);
                var url = await AddImageToFileStore(series.Id, command.Image.FileName, command.Image.Contents, command.Image.MimeType, cancellationToken);

                command.Image.FilePath = url;
                command.Image.IsPublic = true;
                command.Result.File    = await _fileRepository.AddFile(command.Image, cancellationToken);

                command.Result.HasAddedNew = true;

                await _seriesRepository.UpdateSeriesImage(command.LibraryId, command.SeriesId, command.Result.File.Id, cancellationToken);
            }

            return(await base.HandleAsync(command, cancellationToken));
        }
Ejemplo n.º 5
0
        public override async Task <UpdateSeriesRequest> HandleAsync(UpdateSeriesRequest command, CancellationToken cancellationToken = new CancellationToken())
        {
            var result = await _seriesRepository.GetSeriesById(command.LibraryId, command.Series.Id, cancellationToken);

            if (result == null)
            {
                command.Series.Id = default(int);
                var newSeries = await _seriesRepository.AddSeries(command.LibraryId, command.Series, cancellationToken);

                command.Result.HasAddedNew = true;
                command.Result.Series      = newSeries;
            }
            else
            {
                result.Name        = command.Series.Name;
                result.Description = command.Series.Description;
                await _seriesRepository.UpdateSeries(command.LibraryId, result, cancellationToken);

                command.Result.Series = command.Series;
            }

            return(await base.HandleAsync(command, cancellationToken));
        }
Ejemplo n.º 6
0
        public async Task <IActionResult> UpdateSeries([FromBody] SeriesViewModel series)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (series.Id == 0)
            {
                return(BadRequest("A series ID must be specified."));
            }
            series.Seasons = null;
            var entity = await _seriesRepository.GetSeriesById(series.Id);

            if (entity == null)
            {
                return(BadRequest("No series could be found with the specified ID"));
            }
            _mapper.Map(series, entity);
            await _seriesRepository.SaveChanges();

            return(Ok(series));
        }
Ejemplo n.º 7
0
        public SeriesViewModel GetSeriesById(int id, string userId)
        {
            var series = _seriesRepository.GetSeriesById(id, userId);

            return(series);
        }
Ejemplo n.º 8
0
 public IActionResult GetSeriesById(int id) => Ok(_seriesRepository.GetSeriesById(id));