public async Task <BaseResponseModel> UpdateAsync(PrintingEditionModel UpdatePrintingEdition) { BaseResponseModel report = ValidationPrintingEdition(UpdatePrintingEdition); IPrintingEditionsRepository printingEditionsRepository = new PrintingEditionsRepository(_context); PrintingEdition printingEdition = await printingEditionsRepository.GetByIdAsync(UpdatePrintingEdition.Id); printingEdition.AuthorInPrintingEditions = _authorInPrintingEditionsRepository.GetById(UpdatePrintingEdition.Id); printingEdition.Cover = _coverRepository.GetById(UpdatePrintingEdition.Id); if (!report.IsValid) { return(report); } printingEdition.Id = UpdatePrintingEdition.Id; printingEdition.Name = UpdatePrintingEdition.Name; printingEdition.Description = UpdatePrintingEdition.Description; printingEdition.Price = UpdatePrintingEdition.Price; printingEdition.Status = UpdatePrintingEdition.Status; printingEdition.Currency = UpdatePrintingEdition.Currency; printingEdition.Type = UpdatePrintingEdition.Type; printingEdition.Cover.Base64Image = UpdatePrintingEdition.Image; printingEdition.Cover.PrintingEditionId = UpdatePrintingEdition.Id; printingEdition.Cover.PrintingEdition = printingEdition; List <AuthorInPrintingEdition> authorInPrintingEditions = new List <AuthorInPrintingEdition>(); foreach (Guid authorId in UpdatePrintingEdition.AuthorId) { AuthorInPrintingEdition authorInPrintingEdition = new AuthorInPrintingEdition(); authorInPrintingEdition.Author = await _authorRepository.GetByIdAsync(authorId); authorInPrintingEditions.Add(authorInPrintingEdition); } printingEdition.AuthorInPrintingEditions = authorInPrintingEditions; await printingEditionsRepository.UpdateAsync(printingEdition); return(report); }
public async Task <PrintingEditionModel> GetByIdAsync(Guid id) { IPrintingEditionsRepository printingEditionsRepository = new PrintingEditionsRepository(_context); PrintingEdition printingEdition = await printingEditionsRepository.GetByIdAsync(id); Cover cover = _coverRepository.GetById(printingEdition.Id); PrintingEditionModel printingEditionModel = new PrintingEditionModel(); printingEditionModel.Id = printingEdition.Id; printingEditionModel.Name = printingEdition.Name; printingEditionModel.Description = printingEdition.Description; printingEditionModel.Type = printingEdition.Type; printingEditionModel.Currency = printingEdition.Currency; printingEditionModel.Price = printingEdition.Price; printingEditionModel.Status = printingEdition.Status; printingEditionModel.AuthorId = _authorInPrintingEditionsRepository.GetAuthors(printingEdition.Id); printingEditionModel.Image = cover.Base64Image; printingEditionModel.AuthorName = _authorInPrintingEditionsRepository.GetAuthorsName(printingEditionModel.AuthorId); return(printingEditionModel); }