Пример #1
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,ProfesorId,MateriaId")] ProfesorMateria profesorMateria)
        {
            if (id != profesorMateria.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(profesorMateria);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ProfesorMateriaExists(profesorMateria.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["MateriaId"]  = new SelectList(_context.Materia, "Id", "Nombre", profesorMateria.MateriaId);
            ViewData["ProfesorId"] = new SelectList(_context.Profesor, "Id", "NombreApellido", profesorMateria.ProfesorId);
            return(View(profesorMateria));
        }
Пример #2
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,Nombre,MateriaId")] MateriaCursada materiaCursada)
        {
            if (id != materiaCursada.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(materiaCursada);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!MateriaCursadaExists(materiaCursada.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["MateriaId"] = new SelectList(_context.Materia, "Id", "Nombre", materiaCursada.MateriaId);
            return(View(materiaCursada));
        }
Пример #3
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,Nombre,Descripcion,CupoMaximo")] Materia materia)
        {
            if (id != materia.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(materia);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!MateriaExists(materia.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(materia));
        }
Пример #4
0
        public IActionResult Edit(int id, [Bind("Id,Nombre")] Carrera carrera, List <int> materiaIds)
        {
            if (id != carrera.Id)
            {
                return(NotFound());
            }

            ValidarMaterias(materiaIds);

            if (ModelState.IsValid)
            {
                try
                {
                    var carreraDb = _context
                                    .Carrera
                                    .Include(x => x.Materias)
                                    .FirstOrDefault(x => x.Id == id);

                    carreraDb.Nombre = carrera.Nombre;

                    foreach (var carreraMateria in carreraDb.Materias)
                    {
                        _context.Remove(carreraMateria);
                    }

                    foreach (var materiaId in materiaIds)
                    {
                        carreraDb.Materias.Add(new CarreraMateria {
                            CarreraId = carreraDb.Id, MateriaId = materiaId
                        });
                    }

                    _context.Update(carreraDb);
                    _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!CarreraExists(carrera.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }

            ViewData["MateriasId"] = new MultiSelectList(_context.Materia, "Id", "Nombre", materiaIds);

            return(View(carrera));
        }
Пример #5
0
        public async Task <IActionResult> Edit(int id, [Bind("Nombre,Apellido,Legajo,CarreraId,Id")] Alumno alumno)
        {
            ModelState.Remove(nameof(Alumno.Username));
            ModelState.Remove(nameof(Alumno.Role));

            if (id != alumno.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    //Alumno existente en la db
                    Alumno alumnodb = _context.Alumno.Find(alumno.Id);

                    alumnodb.Nombre    = alumno.Nombre;
                    alumnodb.Apellido  = alumno.Apellido;
                    alumnodb.Legajo    = alumno.Legajo;
                    alumnodb.CarreraId = alumno.CarreraId;
                    alumnodb.FechaUltimaModificacion = DateTime.Now;

                    _context.Update(alumnodb);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!AlumnoExists(alumno.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CarreraId"] = new SelectList(_context.Carrera, "Id", "Nombre", alumno.CarreraId);
            return(View(alumno));
        }
Пример #6
0
        public async Task <IActionResult> Edit(int id, [Bind("Nombre,Apellido,Legajo,MateriasAplicables,Id")] Profesor profesor)
        {
            ModelState.Remove(nameof(Profesor.Username));

            if (id != profesor.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    //Profesor existente en la db
                    Profesor profesordb = _context.Profesor.Find(profesor.Id);

                    profesordb.Nombre                  = profesor.Nombre;
                    profesordb.Apellido                = profesor.Apellido;
                    profesordb.Legajo                  = profesor.Legajo;
                    profesordb.MateriasAplicables      = profesor.MateriasAplicables;
                    profesordb.FechaUltimaModificacion = DateTime.Now;

                    _context.Update(profesordb);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ProfesorExists(profesor.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(profesor));
        }