コード例 #1
0
        public ActionResult DeleteFoto(int id, string nomeFoto)
        {
            try
            {
                Cadastro_Produto_Loja cadastro_Produto_Loja = db.CadastroProdutoLoja.Find(id);
                var caminhoArquivo = db.FilePath.Where(x => x.ID_Cadastro_Prod_Loja == id).Where(x => x.Nome_Arquivo == nomeFoto).ToList();
                if (caminhoArquivo.Count > 0)
                {
                    if (caminhoArquivo[0].Caminho_Arquivo != null)
                    {
                        System.IO.File.Delete(caminhoArquivo[0].Caminho_Arquivo);
                    }

                    db.FilePath.Remove(caminhoArquivo[0]);
                }

                //db.CadastroProdutoLoja.Remove(cadastro_Produto_Loja);
                db.SaveChanges();
                return(RedirectToAction("Edit"));
            }
            catch (Exception ex)
            {
                log.Log(LogLevel.Error)
                .Exception(ex)
                .Message("Mensagem de log {0} parametro", 1).Write();
                return(View("Index"));
            }
        }
コード例 #2
0
        public ActionResult GetImagePath(int id)
        {
            Cadastro_Produto_Loja cadastro_Produto_Loja = db.CadastroProdutoLoja.Find(id);
            var caminhoArquivo = db.FilePath.FirstOrDefault(x => x.ID_Cadastro_Prod_Loja == id);

            var Caminho_Arquivo = Path.Combine(@"~\images\uploads", caminhoArquivo.Nome_Arquivo);

            Session["Caminho_Arquivo"] = caminhoArquivo.Nome_Arquivo;

            return(View("Edit", cadastro_Produto_Loja));
        }
コード例 #3
0
        // GET: Catalogo_Produto_Loja/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Cadastro_Produto_Loja catalogo_Produto_Loja = db.CadastroProdutoLoja.Find(id);

            if (catalogo_Produto_Loja == null)
            {
                return(HttpNotFound());
            }
            return(View(catalogo_Produto_Loja));
        }
コード例 #4
0
        public ActionResult GetImage(int id)
        {
            Cadastro_Produto_Loja cadastro_Produto_Loja = db.CadastroProdutoLoja.Find(id);
            var      caminhoArquivo = db.FilePath.Where(x => x.ID_Cadastro_Prod_Loja == id).ToList();
            FilePath foto;
            Utils    utils = new Utils();

            try
            {
                for (int i = 0; i < caminhoArquivo.Count; i++)
                {
                    foto = new FilePath
                    {
                        ID_Cadastro_Prod_Loja = caminhoArquivo[i].ID_Cadastro_Prod_Loja,
                        Nome_Arquivo          = caminhoArquivo[i].Nome_Arquivo,
                        Tipo_Arquivo          = caminhoArquivo[i].Tipo_Arquivo,
                        ID_Caminho            = Convert.ToInt32(caminhoArquivo[0].ID_Caminho),
                        Caminho_Arquivo       = Path.Combine(@"~\images\uploads", caminhoArquivo[i].Nome_Arquivo)
                    };
                    string caminho = "caminho_" + (i + 1);
                    string arqFoto = "arqFoto_" + (i + 1);
                    Session[caminho]  = foto;
                    Session[arqFoto]  = caminhoArquivo[i].Nome_Arquivo;
                    ViewData[caminho] = caminhoArquivo[i].Nome_Arquivo;

                    ViewBag.arqFoto = TempData[arqFoto];

                    //To maintain the state of TempData
                    TempData.Keep();

                    cadastro_Produto_Loja.FilePath.Add(foto);
                }

                Session["Foto"] = cadastro_Produto_Loja;

                return(View("Edit", cadastro_Produto_Loja));
            }
            catch (Exception ex)
            {
                log.Log(LogLevel.Error)
                .Exception(ex)
                .Message("Mensagem de log {0} parametro", 1).Write();
                return(View());
            }
        }
コード例 #5
0
        public ActionResult Create([Bind(Include = "ID_Cadastro_Prod_Loja,Nome_Produto,Modelo_Produto,Descricao_Produto,Preco_Produto,Quantidade_Produto,Status_Produto,Categoria_Produto")] Cadastro_Produto_Loja cadastro_Produto_Loja, HttpPostedFileBase upload1, HttpPostedFileBase upload2, HttpPostedFileBase upload3, HttpPostedFileBase upload4)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    if (upload1 != null && upload1.ContentLength > 0)
                    {
                        var foto = new FilePath
                        {
                            Nome_Arquivo = Guid.NewGuid().ToString() + Path.GetExtension(upload1.FileName),
                            Tipo_Arquivo = Path.GetExtension(upload1.FileName)
                        };
                        foto.Caminho_Arquivo = Path.Combine(Server.MapPath("~/images/uploads"), foto.Nome_Arquivo);
                        upload1.SaveAs(foto.Caminho_Arquivo);
                        cadastro_Produto_Loja.FilePath = new List <FilePath>();
                        cadastro_Produto_Loja.FilePath.Add(foto);
                    }

                    if (upload2 != null && upload2.ContentLength > 0)
                    {
                        var foto = new FilePath
                        {
                            Nome_Arquivo_2 = Guid.NewGuid().ToString() + Path.GetExtension(upload2.FileName),
                            Tipo_Arquivo   = Path.GetExtension(upload2.FileName)
                        };
                        foto.Caminho_Arquivo = Path.Combine(Server.MapPath("~/images/uploads"), foto.Nome_Arquivo_2);
                        upload2.SaveAs(foto.Caminho_Arquivo);
                        cadastro_Produto_Loja.FilePath = new List <FilePath>();
                        cadastro_Produto_Loja.FilePath.Add(foto);
                    }

                    if (upload3 != null && upload3.ContentLength > 0)
                    {
                        var foto = new FilePath
                        {
                            Nome_Arquivo_3 = Guid.NewGuid().ToString() + Path.GetExtension(upload3.FileName),
                            Tipo_Arquivo   = Path.GetExtension(upload3.FileName)
                        };
                        foto.Caminho_Arquivo_3 = Path.Combine(Server.MapPath("~/images/uploads"), foto.Nome_Arquivo_3);
                        upload3.SaveAs(foto.Caminho_Arquivo_3);
                        cadastro_Produto_Loja.FilePath = new List <FilePath>();
                        cadastro_Produto_Loja.FilePath.Add(foto);
                    }

                    if (upload4 != null && upload4.ContentLength > 0)
                    {
                        var foto = new FilePath
                        {
                            Nome_Arquivo_4 = Guid.NewGuid().ToString() + Path.GetExtension(upload4.FileName),
                            Tipo_Arquivo   = Path.GetExtension(upload4.FileName)
                        };
                        foto.Caminho_Arquivo_4 = Path.Combine(Server.MapPath("~/images/uploads"), foto.Nome_Arquivo_4);
                        upload4.SaveAs(foto.Caminho_Arquivo_4);
                        cadastro_Produto_Loja.FilePath = new List <FilePath>();
                        cadastro_Produto_Loja.FilePath.Add(foto);
                    }


                    db.CadastroProdutoLoja.Add(cadastro_Produto_Loja);
                    db.SaveChanges();

                    var      path = Path.Combine(Server.MapPath("~/images/temp"));
                    FileInfo file = new FileInfo(path);
                    if (file.Exists)
                    {
                        file.Delete();
                    }

                    ScriptManager.RegisterStartupScript(page, page.GetType(), "alert", "swalSucesso();", true);
                    return(RedirectToAction("Index"));
                }
                catch (Exception ex)
                {
                    ScriptManager.RegisterStartupScript(page, page.GetType(), "alert", "swalFalhou();", true);
                    log.Log(LogLevel.Error)
                    .Exception(ex)
                    .Message("Mensagem de log {0} parametro", 1).Write();
                    return(RedirectToAction("Index"));
                }
            }

            return(View(cadastro_Produto_Loja));
        }