public async Task <IActionResult> Edit(int id, [Bind("IdCliente,IdKnowProduto,IdKnowLocais,erro,descricao,solucao,obs,versao,Id,DataInclusion,UserName")] KnowBase knowBase) { if (id != knowBase.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(knowBase); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!KnowBaseExists(knowBase.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } //ViewData["IdCliente"] = new SelectList(_context.clientes, "Id", "Id", knowBase.IdCliente); //ViewData["IdKnowLocais"] = new SelectList(_context.knowLocais, "Id", "Id", knowBase.IdKnowLocais); //ViewData["IdKnowProduto"] = new SelectList(_context.knowProduto, "Id", "Id", knowBase.IdKnowProduto); return(View(knowBase)); }
public async Task <IActionResult> Create(int?id, [Bind("erro,descricao,solucao,obs,Id")] KnowBase knowBase, IFormFile[] file, string[] idAnexo) { if (ModelState.IsValid) { List <KnowBaseAnexos> listAnexo = new List <KnowBaseAnexos>(); if (knowBase.Id == id) { for (int i = 0; i < file.Length; i++) { using (var ms = new MemoryStream()) { KnowBaseAnexos anexo = new KnowBaseAnexos(); file[i].CopyTo(ms); anexo.arquivo = ms.ToArray(); anexo.nome = file[i].FileName; anexo.tipo = file[i].ContentType; listAnexo.Add(anexo); } } knowBase.knowbaseanexo = listAnexo; _context.Update(knowBase); await _context.SaveChangesAsync(); } else { for (int i = 0; i < file.Length; i++) { using (var ms = new MemoryStream()) { file[i].CopyTo(ms); listAnexo.Add(new KnowBaseAnexos() { arquivo = ms.ToArray(), nome = file[i].Name, tipo = file[i].ContentType }); } } knowBase.knowbaseanexo = listAnexo; _context.Add(knowBase); await _context.SaveChangesAsync(); } } //ViewData["IdCliente"] = new SelectList(_context.clientes, "Id", "Id", knowBase.IdCliente); //ViewData["IdKnowLocais"] = new SelectList(_context.knowLocais, "Id", "Id", knowBase.IdKnowLocais); //ViewData["IdKnowProduto"] = new SelectList(_context.knowProduto, "Id", "Id", knowBase.IdKnowProduto); //return View(knowBase); return(RedirectToAction(nameof(Index))); }