public async Task AddPrintingEdition(PrintingEditionModel printingEditionModel) { var printingEditionEntity = printingEditionModel.PrintingEditionMapToEntity(); await _printingEditionRepository.Create(printingEditionEntity); var authors = printingEditionModel.Authors; foreach (AuthorModel author in authors) { Author _author = await _authorRepository.FindByName(author.Name); if (_author == null) { _author = new Author { Name = author.Name }; } await _authorInBookRepository.Create(new AuthorInBook { PrintingEdition = printingEditionEntity, Author = _author }); } }
public async Task CreatePrintingEdition(AuthorsInPrintingEditionsViewModel model) { PrintingEdition printingEdition = _mapper.Map <PrintingEdition>(model); var authors = new List <Author>(); var authorsInPrintEdit = new List <AuthorInPrintingEditions>(); await _printEditRepository.Create(printingEdition); foreach (AuthorViewModel authorId in model.AuthorsList) { authors.Add(await _authorRepository.Get(authorId.Id)); } foreach (Author author in authors) { authorsInPrintEdit.Add(new AuthorInPrintingEditions { AuthorId = author.Id, PrintingEditionId = printingEdition.Id }); } _authorInPrintingEditionRepository.AddAuthorInPe(authorsInPrintEdit); }