コード例 #1
0
        public ActionResult Gestion(GestionViewModel model, FormCollection collection)
        {
            var tipoGestion = collection["nHiddenTipoGestion"];
            var id          = collection["nHiddenId"];


            if (!int.TryParse(id, out int idProfesor) || (tipoGestion != "Nuevo" && tipoGestion != "Modificar"))
            {
                return(RedirectToAction("Index", "Universidad", new { mensaje = "Acceso no valido" }));
            }

            model.TipoGestion = tipoGestion;
            model.Sexos       = _sexoServicio.ObtenerTodos().Select(x =>
                                                                    new SelectListItem()
            {
                Value = x.Id.ToString(),
                Text  = x.Descripcion
            }
                                                                    );


            switch (tipoGestion)
            {
            case "Nuevo":
                model.Profesor         = new Profesor();
                model.Profesor.Persona = new Persona();
                model.Profesor.Id      = 0;
                model.Profesor.Activo  = true;
                model.TxtSexo          = "1";
                break;

            case "Modificar":
                var persona = _personaServicio.ObtenerCompleto(6);
                persona.Sexo = _sexoServicio.ObtenerPorId(int.Parse(model.TxtSexo));
                _personaServicio.Modificar(persona);
                break;
            }

            /*
             * if (!ModelState.IsValid)
             *  return View(model);
             *
             * model.Profesor.Persona.Dni = int.Parse(model.TxtDni);
             * model.Profesor.Persona.Apellido = model.TxtApellido;
             * model.Profesor.Persona.Nombre = model.TxtNombre;
             * model.Profesor.Persona.FechaNacimiento = DateTime.Parse(model.TxtNacimiento);
             * model.Profesor.Persona.Sexo = _sexoServicio.ObtenerPorId(int.Parse(model.TxtSexo));
             * model.Profesor.Activo = model.TxtActivo == "SI"? true : false;
             *
             * switch (tipoGestion)
             * {
             *  case "Nuevo":
             *      _profesorServicio.AgragarProfesor(model.Profesor);
             *      break;
             *  case "Modificar":
             *      _profesorServicio.ModificarProfesor(model.Profesor);
             *      break;
             *  default:
             *      return RedirectToAction("Index", "Universidad", new { mensaje = "Acceso no valido" });
             * }
             */
            return(RedirectToAction("Index", "Profesor"));
        }