public ActionResult ExcluirAnexo(int codigo) { using (var bll = new ParecerSolicitacaoBLL()) { var p = Session["Parecer"] as ParecerSolicitacao; var anxBLL = new DocumentoAnexadoAprovacaoBLL(); try { var anx = p.DocumentosAnexadosAprovacao.Where(c => c.CodDocumentoAnexadoApr == codigo).Single(); p.DocumentosAnexadosAprovacao.Remove(anx); anxBLL.Excluir(anx); } catch (Exception ex) { return Json(new { erro = ex.Message }, JsonRequestBehavior.DenyGet); } Session["Parecer"] = p; return Json(new { msg = "Anexo excluido" }, JsonRequestBehavior.DenyGet); } }
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 p = Session["Parecer"] as ParecerSolicitacao; using (var documentoBLL = new DocumentoAnexadoAprovacaoBLL()) { 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 caminhoUploads = ConfigurationManager.AppSettings["caminhoUploads"]; var anexo = new DocumentoAnexadoAprovacao(); anexo.NomDocumento = p.Solicitacao.Codigo + "_" + p.CodParecer + "_" + uploadArquivo.FileName; anexo.TamanhoEmBytes = uploadArquivo.ContentLength; anexo.DataEnvio = DateTime.Now; anexo.TipoDocumento = TipoDocumento; anexo.CodTipoDocumento = int.Parse(TipoDocumento); anexo.Parecer = p; documentoBLL.Salvar(anexo); string filePath = Path.Combine(Server.MapPath(caminhoUploads), Path.GetFileName(anexo.NomDocumento)); uploadArquivo.SaveAs(filePath); p.DocumentosAnexadosAprovacao.Add(anexo); Session["Parecer"] = p; 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); } }