コード例 #1
0
        public ActionResult UploadFileAssinante(HttpPostedFileBase file)
        {
            if ((String)Session["Ativa"] == null)
            {
                return(RedirectToAction("Login", "ControleAcesso"));
            }
            if (file == null)
            {
                ModelState.AddModelError("", SMS_Resource.ResourceManager.GetString("M0019", CultureInfo.CurrentCulture));
                return(RedirectToAction("VoltarAnexoAssinante"));
            }

            Int32     id       = (Int32)Session["IdVolta"];
            ASSINANTE item     = assApp.GetById(id);
            USUARIO   usu      = (USUARIO)Session["UserCredentials"];
            var       fileName = Path.GetFileName(file.FileName);

            if (fileName.Length > 100)
            {
                ModelState.AddModelError("", SMS_Resource.ResourceManager.GetString("M0020", CultureInfo.CurrentCulture));
                return(RedirectToAction("VoltarAnexoAssinante"));
            }
            String caminho = "/Imagens/Assinantes/" + item.ASSI_CD_ID.ToString() + "/Anexos/";
            String path    = Path.Combine(Server.MapPath(caminho), fileName);

            file.SaveAs(path);

            //Recupera tipo de arquivo
            extensao = Path.GetExtension(fileName);
            String a = extensao;

            // Gravar registro
            ASSINANTE_ANEXO foto = new ASSINANTE_ANEXO();

            foto.ASAN_AQ_ARQUIVO = "~" + caminho + fileName;
            foto.ASAN_DT_ANEXO   = DateTime.Today;
            foto.ASA_IN_ATIVO    = 1;
            Int32 tipo = 3;

            if (extensao.ToUpper() == ".JPG" || extensao.ToUpper() == ".GIF" || extensao.ToUpper() == ".PNG" || extensao.ToUpper() == ".JPEG")
            {
                tipo = 1;
            }
            if (extensao.ToUpper() == ".MP4" || extensao.ToUpper() == ".AVI" || extensao.ToUpper() == ".MPEG")
            {
                tipo = 2;
            }
            foto.ASAN_IN_TIPO   = tipo;
            foto.ASAN_NM_TITULO = fileName;
            foto.ASSI_CD_ID     = item.ASSI_CD_ID;

            item.ASSINANTE_ANEXO.Add(foto);
            Int32 volta = assApp.ValidateEdit(item);

            return(RedirectToAction("VoltarAnexoAssinante"));
        }
コード例 #2
0
        public ActionResult VerAnexoAssinante(Int32 id)
        {
            // Prepara view
            if ((String)Session["Ativa"] == null)
            {
                return(RedirectToAction("Login", "ControleAcesso"));
            }
            ASSINANTE_ANEXO item = assApp.GetAnexoById(id);

            return(View(item));
        }
コード例 #3
0
        public FileResult DownloadAssinante(Int32 id)
        {
            ASSINANTE_ANEXO item         = assApp.GetAnexoById(id);
            String          arquivo      = item.ASAN_AQ_ARQUIVO;
            Int32           pos          = arquivo.LastIndexOf("/") + 1;
            String          nomeDownload = arquivo.Substring(pos);
            String          contentType  = string.Empty;

            if (arquivo.Contains(".pdf"))
            {
                contentType = "application/pdf";
            }
            else if (arquivo.Contains(".jpg"))
            {
                contentType = "image/jpg";
            }
            else if (arquivo.Contains(".png"))
            {
                contentType = "image/png";
            }
            return(File(arquivo, contentType, nomeDownload));
        }