public int InserirArquivo(ArquivoPericia ArquivoPericia)
        {
            StringBuilder SQL = new StringBuilder();

            SQL.AppendLine("INSERT INTO dbo.tb_leilao_lotes_pericia_arquivos (id_lote, nome, tamanho, tipo, path, usuario)   ");
            SQL.AppendFormat("VALUES ({0}, '{1}', {2}, '{3}', '{4}', '{5}')", ArquivoPericia.Id_Lote,
                             ArquivoPericia.Nome,
                             ArquivoPericia.Tamanho,
                             ArquivoPericia.Tipo,
                             ArquivoPericia.Path,
                             ArquivoPericia.Usuario);
            try
            {
                return(ExecutaSQL(SQL.ToString()));
            }
            catch (Exception e)
            {
                throw e;
            }
        }
Example #2
0
        public JsonResult CarregaArquivo(int?id)
        {
            var r = new List <ArquivoPericia>();

            try
            {
                foreach (string file in Request.Files)
                {
                    HttpPostedFileBase hpf = Request.Files[file] as HttpPostedFileBase;
                    if (hpf.ContentLength == 0)
                    {
                        continue;
                    }

#if DEBUG
                    string savedFileName = Path.Combine(Server.MapPath("~/App_Data"), Path.GetFileName(hpf.FileName));
#else
                    string savedFileName = Path.Combine(Server.MapPath("~/Arquivos"), Path.GetFileName(hpf.FileName));
#endif

                    hpf.SaveAs(savedFileName);

                    ArquivoPericia ArquivoPericia = new ArquivoPericia()
                    {
                        Id_Lote = id.Value,
                        Nome    = hpf.FileName,
                        Tamanho = hpf.ContentLength,
                        Tipo    = hpf.ContentType,
                        Path    = savedFileName,
                        Usuario = User.Identity.Name
                    };

                    r.Add(ArquivoPericia);

                    RepositorioGlobal.Pericia.InserirArquivo(ArquivoPericia);
                }
            }
            catch (Exception e)
            {
                throw new Exception("caiu aqui");
            }



            if (r.Count > 0)
            {
                var json = JsonConvert.SerializeObject(r);

                return(Json(new { ArquivoPericia = r }, JsonRequestBehavior.AllowGet));

                //var res = Content("{\"name\":\"" + r[0].Nome + "\",\"type\":\"" + r[0].Tipo + "\",\"size\":\"" + string.Format("{0} bytes", r[0].Tamanho) + "\"}", "application/json");

                //return new JsonResult();

                //return Content(json, "application/json");
            }
            else
            {
                return(Json(new { ArquivoPericia = new ArquivoPericia() }, JsonRequestBehavior.AllowGet));
            }
        }