Пример #1
0
        public ActionResult EliminarT(int ID)
        {
            TiendasViewModel model = new TiendasViewModel();

            using (TredaEntities db = new TredaEntities())
            {
                var oTienda = db.Tiendas.Find(ID);
                db.Tiendas.Remove(oTienda);
                db.SaveChanges();
            }
            return(Redirect("~/Tiendas/"));
        }
Пример #2
0
        public ActionResult EditarT(int ID)
        {
            TiendasViewModel model = new TiendasViewModel();

            using (TredaEntities db = new TredaEntities())
            {
                var oTienda = db.Tiendas.Find(ID);
                model.Nombre            = oTienda.Nombre;
                model.Fecha_de_Apertura = oTienda.Fecha_de_Apertura;
                model.ID = oTienda.ID;
            }
            return(View(model));
        }
Пример #3
0
        public async Task <IActionResult> ListAll(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var tienda = await _context.Tienda
                         .FirstOrDefaultAsync(m => m.ID == id);

            var juegos = await _context.Juegos.Include(j => j.Tienda).Where
                             (m => m.Tienda.Nombre == tienda.Nombre).ToListAsync();

            var consolas = await _context.Consolas.Include(j => j.Tienda).Include(j => j.Marca).Where
                               (m => m.Tienda.Nombre == tienda.Nombre).ToListAsync();

            var perifericos = await _context.Perifericos.Include(j => j.Tienda).Include(j => j.Marca).Where
                                  (m => m.Tienda.Nombre == tienda.Nombre).ToListAsync();

            TiendasViewModel myModel = new TiendasViewModel();

            if (juegos.Count > 0)
            {
                myModel.Juegos = juegos;
            }

            if (consolas.Count > 0)
            {
                myModel.Consolas = consolas;
            }

            if (perifericos.Count > 0)
            {
                myModel.Perifericos = perifericos;
            }

            if (tienda == null)
            {
                return(NotFound());
            }

            return(View(myModel));
        }
Пример #4
0
        public ActionResult EditarT(TiendasViewModel model)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    using (TredaEntities db = new TredaEntities())
                    {
                        var oTabla = db.Tiendas.Find(model.ID);
                        oTabla.Nombre            = model.Nombre;
                        oTabla.Fecha_de_Apertura = model.Fecha_de_Apertura;

                        db.Entry(oTabla).State = System.Data.Entity.EntityState.Modified;
                        db.SaveChanges();
                    }
                    return(Redirect("~/Tiendas/"));
                }
                return(View(model));
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
Пример #5
0
        public ActionResult NuevaT(TiendasViewModel model)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    using (TredaEntities db = new TredaEntities())
                    {
                        var oTabla = new Tiendas();
                        oTabla.Nombre            = model.Nombre;
                        oTabla.Fecha_de_Apertura = model.Fecha_de_Apertura;

                        db.Tiendas.Add(oTabla);
                        db.SaveChanges();
                    }
                    return(Redirect("~/Tiendas/"));
                }
                return(View(model));
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }