public void PreencheDependencias(DocumentoAnexado anx) { using (var tipoDocBLL = new TipoDocumentoDAL()) { var tipos = tipoDocBLL.ListarTodos(); foreach (var t in tipos) { var codTipo = Convert.ToInt32(t.CodTipoDocumento); anx.TiposDocumento.Add(codTipo, t.NomTipo); } } }
public ActionResult SalvarAnexo(HttpPostedFileBase uploadArquivo, String TipoDocumento) { try { if (uploadArquivo == null) { // submeter a solicitação para integração, pois é o ultimo passo do wizard. return Json(new { msg = "Nenhum arquivo enviado." }, JsonRequestBehavior.DenyGet); } else { var s = Session["Solicitacao"] as Solicitacao; using (var documentoBLL = new DocumentoAnexadoSolicitacaoBLL()) { if (uploadArquivo.ContentLength > 0) { try { if (uploadArquivo.ContentLength > 4000000) { return Json(new { erro = "Erro ao tentar gravar registro de documento\n O Tamanho do arquivo excede o limite de upload único suportado pelo servidor (4MB)" }, "application/json", JsonRequestBehavior.DenyGet); } var anexo = new DocumentoAnexado(); anexo.NomDocumento = s.Codigo + "_" + uploadArquivo.FileName; anexo.TamanhoEmBytes = uploadArquivo.ContentLength; anexo.DataEnvio = DateTime.Now; anexo.TipoDocumento = TipoDocumento; anexo.CodTipoDocumento = int.Parse(TipoDocumento); anexo.Solicitacao = s; var caminhoUploads = ConfigurationManager.AppSettings["caminhoUploads"]; string filePath = Path.Combine(Server.MapPath(caminhoUploads), Path.GetFileName(anexo.NomDocumento)); uploadArquivo.SaveAs(filePath); documentoBLL.Salvar(anexo); s.DocumentosAnexados.Add(anexo); Session["Solicitacao"] = s; return Json(new { msg = "Arquivo Gravado", arq = anexo.NomDocumento }, JsonRequestBehavior.DenyGet); } catch (Exception ex) { return Json(new { erro = "Erro ao tentar gravar registro de documento: " + ex.Message }, JsonRequestBehavior.DenyGet); } } } return Json("teste", JsonRequestBehavior.DenyGet); } } catch (Exception ex) { return Json(new { erro = ex.Message }, JsonRequestBehavior.DenyGet); } }