Exemplo n.º 1
0
        public void UpdatePrintingEdition(PrintingEditionModel printingEdition)
        {
            _validator.ValidatePrintingEdition(printingEdition);
            var dbPrintingEdition = _printingEditionRepository.GetById(printingEdition.Id);

            if (dbPrintingEdition is null)
            {
                throw new CustomApiException(HttpStatusCode.BadRequest, Constants.PRINTINGEDITIONNOTFOUNDERROR);
            }
            _mapper.Map(printingEdition, dbPrintingEdition);
            var authorFilter = new AuthorFilterModel {
                EditionAuthors = printingEdition.Authors
            };
            var authors = _authorRepository.GetAll(authorFilter);

            dbPrintingEdition.Authors.Clear();
            var dbAuthors = dbPrintingEdition.Authors.ToList();

            dbAuthors.AddRange(authors);
            dbPrintingEdition.Authors = dbAuthors;
            _printingEditionRepository.Update(dbPrintingEdition);
        }