Exemple #1
0
        public async Task <PrintingEditionModel> UpdateEditionAsync(PrintingEditionItemModel model)
        {
            var printingEdition = await _editionRepository.GetEditionByTitle(model.Title, model.Id);

            if (printingEdition is null)
            {
                var editionToUpdate = _mapper.Map <PrintingEditionItemModel, PrintingEdition>(model);
                var editionUpdated  = await _editionRepository.UpdateEditionAsync(editionToUpdate);

                var authorsInPrintingEdition =
                    AuthorInPrintingEditionProvider.GetAuthorInPrintingEditionList(model.Authors,
                                                                                   editionUpdated.Id);

                await _authorInPeRepository.UpdateAuthorsInPrintingEditionAsync(authorsInPrintingEdition,
                                                                                editionUpdated.Id);

                printingEdition = await _editionRepository.GetEditionByIdAsync(editionUpdated.Id.ToString());

                var printingEditionModel = _mapper.Map <PrintingEdition, PrintingEditionModel>(printingEdition);

                return(printingEditionModel);
            }

            throw new ServerException(Constants.Errors.EDITION_ALREADY_EXIST, Enums.Errors.BadRequest);
        }
Exemple #2
0
        public async Task <PrintingEditionModel> CreateEditionAsync(PrintingEditionItemModel model)
        {
            var printingEdition = await _editionRepository.GetEditionByTitle(model.Title);

            if (printingEdition is null)
            {
                var editionToAdd = _mapper.Map <PrintingEditionItemModel, PrintingEdition>(model);
                var editionAdded = await _editionRepository.CreateEditionAsync(editionToAdd);

                if (model.Authors.Count > 1)
                {
                    var authorInPrintingEditions =
                        AuthorInPrintingEditionProvider.GetAuthorInPrintingEditionList(model.Authors, editionAdded.Id);

                    await _authorInPeRepository.AddAuthorsToPrintingEditionAsync(authorInPrintingEditions);
                }
                else
                {
                    var authorInPrintingEdition =
                        AuthorInPrintingEditionProvider.GetAuthorInPrintingEdition(editionAdded.Id, model.Authors[0]);

                    await _authorInPeRepository.AddAuthorToPrintingEditionAsync(authorInPrintingEdition);
                }

                printingEdition = await _editionRepository.GetEditionByIdAsync(editionAdded.Id.ToString());

                var printingEditionModel = _mapper.Map <PrintingEdition, PrintingEditionModel>(printingEdition);

                return(printingEditionModel);
            }

            throw new ServerException(Constants.Errors.EDITION_ALREADY_EXIST, Enums.Errors.BadRequest);
        }
Exemple #3
0
        public async Task <IActionResult> UpdateEdition([FromBody] PrintingEditionItemModel model)
        {
            if (ModelState.IsValid)
            {
                return(Ok(await _editionService.UpdateEditionAsync(model)));
            }

            return(BadRequest());
        }