public ActionResult Copy(GramaticasMoveViewModel viewModel)
        {
            int       id        = viewModel.Gramatica.GramaticaId;
            Gramatica gramatica = db.Gramaticas.Include(gra => gra.GramaticaCuerpo).Include(g => g.Vocabularios).FirstOrDefault(g => g.GramaticaId == id);

            var subtemaOrigen = db.SubTemas.Include(s => s.Tema).SingleOrDefault(s => s.SubTemaId == gramatica.SubTemaId);

            if (gramatica != null)
            {
                //copia de gramatica y vocabularios
                Gramatica gramaticaNuevo = new Gramatica();
                gramaticaNuevo           = gramatica;
                gramaticaNuevo.SubTemaId = viewModel.SubTemaCopiarId;

                //orden
                int nuevoOrden = db.Gramaticas.Where(g => g.SubTemaId == viewModel.SubTemaCopiarId).Count();
                gramaticaNuevo.Orden = nuevoOrden + 1;

                db.Gramaticas.Add(gramaticaNuevo);
                db.SaveChanges();


                return(RedirectToAction("Index", "Bloques", new { id = gramaticaNuevo.SubTemaId, pestanya = (int)PestanyasBloques.Gramaticas }));
            }

            viewModel.InicializarDesplegables();
            return(View(viewModel));
        }
        public ActionResult Move(GramaticasMoveViewModel viewModel)
        {
            int       id        = viewModel.Gramatica.GramaticaId;
            Gramatica gramatica = db.Gramaticas.Find(id);
            var       subtema   = db.SubTemas.Include(s => s.Tema).SingleOrDefault(s => s.SubTemaId == gramatica.SubTemaId);

            viewModel.SubTema   = subtema;
            viewModel.Gramatica = gramatica;
            if (gramatica != null)
            {
                //Ordenar de nuevo todas los Gramaticas
                foreach (Gramatica gr in db.Gramaticas.Where(b => b.SubTemaId == gramatica.SubTemaId && b.Orden > gramatica.Orden).ToList())
                {
                    gr.Orden = (gr.Orden) - 1;

                    db.Entry(gr).State = EntityState.Modified;
                }
                db.SaveChanges();

                viewModel.Gramatica.SubTemaId       = viewModel.SubTemaCopiarId;
                viewModel.Gramatica.Orden           = db.Gramaticas.Count(grama => grama.SubTemaId == viewModel.SubTemaCopiarId) + 1;
                db.Entry(viewModel.Gramatica).State = EntityState.Modified;
                db.SaveChanges();

                return(RedirectToAction("Index", "Bloques", new { id = viewModel.Gramatica.SubTemaId, pestanya = (int)PestanyasBloques.Gramaticas }));
            }

            viewModel.InicializarDesplegables();
            return(View(viewModel));
        }
        // GET: Admin/Gramaticas/Copy
        public ActionResult Copy(int id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Gramatica gramatica = db.Gramaticas.Find(id);

            if (gramatica == null)
            {
                return(HttpNotFound());
            }
            var subtema = db.SubTemas.Include(s => s.Tema).SingleOrDefault(s => s.SubTemaId == gramatica.SubTemaId);

            GramaticasMoveViewModel viewModel = new GramaticasMoveViewModel();

            viewModel.Gramatica = gramatica;
            viewModel.SubTema   = subtema;
            viewModel.InicializarDesplegables();

            return(View(viewModel));
        }