コード例 #1
0
        public ActionResult Create([Bind(Include = "Id,OpcionCorrecta,Pregunta,descA,descB,descC,descD")] OpcionViewModel opcionViewModel)

        {
            Opcion objeto_arreglo = new Opcion();

            if (ModelState.IsValid)
            {
                /*Objeto instanciado del modelo Opcion*/

                int id_pregunta = ObtenerIdPregunta(opcionViewModel.Pregunta);

                /*Arreglos auxiliares*/
                string[] array_opciones = { opcionViewModel.descA, opcionViewModel.descB, opcionViewModel.descC, opcionViewModel.descD };
                string[] array_titulo   = { "A", "B", "C", "D" };
                int[]    opcion_a       = { 1, 0, 0, 0 };
                int[]    opcion_b       = { 0, 1, 0, 0 };
                int[]    opcion_c       = { 0, 0, 1, 0 };
                int[]    opcion_d       = { 0, 0, 0, 1 };
                objeto_arreglo.IdPreguntaOpcion = id_pregunta;
                /*Llenado del vector con las cuatro opciones*/
                for (int i = 0; i < array_opciones.Length; i++)
                {
                    objeto_arreglo.Titulo      = array_titulo[i];
                    objeto_arreglo.Descripcion = array_opciones[i];
                    /*Validacion para la opc_correcta*/
                    if (opcionViewModel.OpcionCorrecta == "A")
                    {
                        objeto_arreglo.OpcionCorrecta = opcion_a[i];
                    }
                    else if (opcionViewModel.OpcionCorrecta == "B")
                    {
                        objeto_arreglo.OpcionCorrecta = opcion_b[i];
                    }
                    else if (opcionViewModel.OpcionCorrecta == "C")
                    {
                        objeto_arreglo.OpcionCorrecta = opcion_c[i];
                    }
                    else if (opcionViewModel.OpcionCorrecta == "D")
                    {
                        objeto_arreglo.OpcionCorrecta = opcion_d[i];
                    }
                    db.Opciones.Add(objeto_arreglo);
                    db.SaveChanges();
                }

                /*Inserción de los datos*/


                return(RedirectToAction("Index"));
            }

            ViewBag.IdPreguntaOpcion = new SelectList(db.Pregunta, "Id", "Descripcion", objeto_arreglo.IdPreguntaOpcion);
            return(View(objeto_arreglo));
        }
コード例 #2
0
 public ActionResult DeleteOpcion(OpcionViewModel vm)
 {
     try
     {
         var Opcion = Mapper.Map(vm, new Opcion());
         dbEntity.Opciones.Attach(Opcion);
         dbEntity.Opciones.Remove(Opcion);
         dbEntity.SaveChanges();
         return Json(new { Result = "OK", Message = "Elemento Eliminado." });
     }
     catch (Exception ex)
     {
         return Json(new { Result = "Error", Message = ex.StackTrace });
     }
 }
コード例 #3
0
 public ActionResult DeleteOpcionFromRol(OpcionViewModel opcion, string roleId)
 {
     try
     {
         var entity = (from e in dbEntity.RolOpciones
                      where e.OpcionId == opcion.Id && e.RoleId == roleId
                      select e).First();
         dbEntity.RolOpciones.Remove(entity);
         dbEntity.SaveChanges();
         return Json(new { Result = "OK", Message = "Elemento Eliminado." });
     }
     catch (Exception ex)
     {
         return Json(new { Result = "Error", Message = ex.StackTrace });
     }
 }
コード例 #4
0
                    public override void MapearDesde(DetalleInformeInspeccion detalleInformeInspeccion)
                    {
                        base.MapearDesde(detalleInformeInspeccion);

                        OpcionesReparacion.Clear();
                        OpcionesAtencion.Clear();

                        foreach (var opcion in (detalleInformeInspeccion as DetalleGrupoSistemaComponente).OpcionesAtencion)
                        {
                            OpcionViewModel opcionViewModel = new OpcionViewModel();
                            opcionViewModel.MapearDesde(opcion);
                            OpcionesAtencion.Add(opcionViewModel);
                        }

                        foreach (var opcion in (detalleInformeInspeccion as DetalleGrupoSistemaComponente).OpcionesReparacion)
                        {
                            OpcionViewModel opcionViewModel = new OpcionViewModel();
                            opcionViewModel.MapearDesde(opcion);
                            OpcionesReparacion.Add(opcionViewModel);
                        }
                    }
コード例 #5
0
                    public override void MapearDesde(DetalleInformeInspeccion detalleInformeInspeccion)
                    {
                        base.MapearDesde(detalleInformeInspeccion);

                        OpcionesDesgaste.Clear();
                        OpcionesReparacion.Clear();

                        foreach (var opcion in (detalleInformeInspeccion as DetalleGrupoDesgasteLlanta).OpcionesDesgaste)
                        {
                            OpcionViewModel opcionViewModel = new OpcionViewModel();
                            opcionViewModel.MapearDesde(opcion);
                            OpcionesDesgaste.Add(opcionViewModel);
                        }

                        foreach (var opcion in (detalleInformeInspeccion as DetalleGrupoDesgasteLlanta).OpcionesReparacion)
                        {
                            OpcionViewModel opcionViewModel = new OpcionViewModel();
                            opcionViewModel.MapearDesde(opcion);
                            OpcionesReparacion.Add(opcionViewModel);
                        }
                    }
コード例 #6
0
        public ActionResult Edit([Bind(Include = "opciones.Id,OpcionCorrecta,Pregunta,descA,descB,descC,descD,idAuxiliarPregunta")] OpcionViewModel opcionViewModel)
        {
            int id_pregunta = opcionViewModel.idAuxiliarPregunta;

            if (ModelState.IsValid)
            {
                /*Consulta en LINQ para eliminar las opciones*/
                int[] vector_id_opcion = new int[4];
                int   i         = 0;
                var   id_opcion = db.Opciones.Where(o => o.IdPreguntaOpcion.Equals(id_pregunta));
                foreach (var Opciones in id_opcion)
                {
                    vector_id_opcion[i] = Opciones.Id;
                    i++;
                }
                for (int j = 0; j < vector_id_opcion.Length; j++)
                {
                    Opcion opcion = db.Opciones.Find(vector_id_opcion[j]);
                    db.Opciones.Remove(opcion);
                    db.SaveChanges();
                }
                /*Consulta en LINQ para insertar las nuevas opciones*/
                Opcion objeto_arreglo = new Opcion();
                /*Objeto instanciado del modelo Opcion*/

                /*Arreglos auxiliares*/
                string[] array_opciones = { opcionViewModel.descA, opcionViewModel.descB, opcionViewModel.descC, opcionViewModel.descD };
                string[] array_titulo   = { "A", "B", "C", "D" };
                int[]    opcion_a       = { 1, 0, 0, 0 };
                int[]    opcion_b       = { 0, 1, 0, 0 };
                int[]    opcion_c       = { 0, 0, 1, 0 };
                int[]    opcion_d       = { 0, 0, 0, 1 };
                objeto_arreglo.IdPreguntaOpcion = id_pregunta;
                /*Llenado del vector con las cuatro opciones*/
                for (int h = 0; h < array_opciones.Length; h++)
                {
                    objeto_arreglo.Titulo      = array_titulo[h];
                    objeto_arreglo.Descripcion = array_opciones[h];
                    /*Validacion para la opc_correcta*/
                    if (opcionViewModel.OpcionCorrecta == "A")
                    {
                        objeto_arreglo.OpcionCorrecta = opcion_a[h];
                    }
                    else if (opcionViewModel.OpcionCorrecta == "B")
                    {
                        objeto_arreglo.OpcionCorrecta = opcion_b[h];
                    }
                    else if (opcionViewModel.OpcionCorrecta == "C")
                    {
                        objeto_arreglo.OpcionCorrecta = opcion_c[h];
                    }
                    else if (opcionViewModel.OpcionCorrecta == "D")
                    {
                        objeto_arreglo.OpcionCorrecta = opcion_d[h];
                    }
                    db.Opciones.Add(objeto_arreglo);
                    db.SaveChanges();
                }
                return(RedirectToAction("Index"));
            }

            return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
        }
コード例 #7
0
        public ActionResult SaveOpcion(OpcionViewModel vm)
        {
            if (ModelState.ContainsKey("FechaRegistro"))
            {
                ModelState["FechaRegistro"].Errors.Clear();
            }
            var Opcion = Mapper.Map(vm, new Opcion());
            if (ModelState.IsValid)
            {
                string mensaje = "";
                if (Opcion.Id > 0)
                {
                    dbEntity.Opciones.Attach(Opcion);
                    dbEntity.Entry(Opcion).State = EntityState.Modified;
                    dbEntity.SaveChanges();
                    mensaje = "Datos Actualizados.";
                }
                else
                {
                    dbEntity.Opciones.Add(Opcion);
                    dbEntity.SaveChanges();
                    mensaje = "Opción Creada";
                }
                vm.Id = Opcion.Id;
                return Json(new { Result = "OK", Data = vm, Message = mensaje });
            }

            return Json(new { Result = "ERROR", Message = "Hay Datos erroneos" });
        }