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); }