Esempio n. 1
0
        public ActionResult Editar(ListaArmas model)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    using (poligonoEntities db = new poligonoEntities())
                    {
                        var oArma = db.arma.Find(model.Idarma);
                        oArma.nombre_arma  = model.nombrearma;
                        oArma.modelo       = model.modelo;
                        oArma.foto         = model.foto;
                        oArma.numero_serie = model.numeroserie;

                        db.Entry(oArma).State = System.Data.Entity.EntityState.Modified;
                        db.SaveChanges();
                    }
                    return(Redirect("~/Armas/"));
                }
                return(View(model));
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
Esempio n. 2
0
        public ActionResult Nuevo(ListaArmas model)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    using (poligonoEntities db = new poligonoEntities())
                    {
                        var oArma = new arma();
                        oArma.nombre_arma  = model.nombrearma;
                        oArma.modelo       = model.modelo;
                        oArma.foto         = model.foto;
                        oArma.numero_serie = model.numeroserie;

                        db.arma.Add(oArma);
                        db.SaveChanges();
                    }
                    return(Redirect("~/Armas/"));
                }
                return(View(model));
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
Esempio n. 3
0
        public ActionResult Editar(int Idarma)
        {
            ListaArmas model = new ListaArmas();

            using (poligonoEntities db = new poligonoEntities())
            {
                var oArma = db.arma.Find(Idarma);
                model.nombrearma  = oArma.nombre_arma;
                model.modelo      = oArma.modelo;
                model.foto        = oArma.foto;
                model.numeroserie = oArma.numero_serie;
            }
            return(View(model));
        }
Esempio n. 4
0
        public ActionResult Nuevo(ListaArmas model, HttpPostedFileBase foto)

        {
            try
            {
                if (ModelState.IsValid)
                {
                    /*if (imagen.ContentLength > 0)
                     * {
                     *  string relativePath = "~/Temp/" + Path.GetFileName(imagen.FileName);
                     *  string physicalPath = Server.MapPath(relativePath);
                     *  imagen.SaveAs(physicalPath);
                     *  //return View((object)relativePath);
                     * }*/

                    if (foto != null)
                    {
                        string image1 = foto.FileName;
                        model.foto = image1;
                        var image1Path = Path.Combine(Server.MapPath("~/Temp"), image1);
                        foto.SaveAs(image1Path);
                    }

                    using (Context db = new Context())

                    {
                        var oArma = new arma();
                        oArma.nombre_arma  = model.nombrearma;
                        oArma.modelo       = model.modelo;
                        oArma.foto         = model.foto;
                        oArma.numero_serie = model.numeroserie;

                        db.Arma.Add(oArma);
                        db.SaveChanges();
                    }
                    return(Redirect("~/Armas/"));
                }
                return(View(model));
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
Esempio n. 5
0
        public ActionResult Editar(ListaArmas model, HttpPostedFileBase foto)

        {
            try
            {
                if (ModelState.IsValid)
                {
                    using (Context db = new Context())

                        if (foto != null)
                        {
                            string image1 = foto.FileName;
                            model.foto = image1;
                            var image1Path = Path.Combine(Server.MapPath("~/Temp"), image1);
                            foto.SaveAs(image1Path);
                        }

                    using (Context db = new Context())

                    {
                        var oArma = db.Arma.Find(model.Idarma);
                        oArma.nombre_arma = model.nombrearma;
                        oArma.modelo      = model.modelo;


                        if (foto != null)
                        {
                            oArma.foto = model.foto;
                        }

                        oArma.numero_serie = model.numeroserie;

                        db.Entry(oArma).State = System.Data.Entity.EntityState.Modified;
                        db.SaveChanges();
                    }
                    return(Redirect("~/Armas/"));
                }
                return(View(model));
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
Esempio n. 6
0
 void Start()
 {
     lArmas = FindObjectOfType <ListaArmas>();
     BusquedaArmas(Id);
 }