public async Task <ActionResult <Manga_Generos> > PostManga(Manga_Generos manga_generos) { _context.MANGAS.Add(manga_generos.DtoManga); await _context.SaveChangesAsync(); foreach (var item in manga_generos.GenerosSelected) { var dtoManga_Generos = new DTOManga_Generos { ID_MANGA = manga_generos.DtoManga.ID_MANGA, ID_GENERO = item }; _context.MANGA_GENEROS.Add(dtoManga_Generos); } await _context.SaveChangesAsync(); return(manga_generos); }
public async Task <IActionResult> PostAdicionarManga(MangaGenerosSituacaoModel modelManga) { if (!ModelState.IsValid) { return(RedirectToAction("AdicionarManga")); } foreach (var item in modelManga.Capa) { if (item.Length > 0) { using var stream = new MemoryStream(); await item.CopyToAsync(stream); modelManga.DtoManga.CAPA = stream.ToArray(); } } try { var manga_generos = new Manga_Generos { DtoManga = modelManga.DtoManga, GenerosSelected = modelManga.GenerosSelected }; var json = JsonConvert.SerializeObject(manga_generos); var contentString = new StringContent(json, Encoding.UTF8, "application/json"); var response = await client.PostAsync($"{urlApi}/Mangas", contentString); return(RedirectToAction("Index")); } catch (Exception) { return(RedirectToAction("AdicionarManga")); } }