Beispiel #1
0
        public async Task <Cursos> PostCursos(Cursos curso)
        {
            _context.Cursos.Add(curso);
            await _context.SaveChangesAsync();

            return(await Task.FromResult(curso));
        }
Beispiel #2
0
        public async Task <IActionResult> PutEvaluaciones(int id, Evaluaciones evaluacion)
        {
            Profesores profesor = await ComprobacionSesion.ComprobarInicioSesion(HttpContext.Request.Headers, _context);

            if (profesor == null)
            {
                return(BadRequest());
            }

            if (id != evaluacion.Id)
            {
                return(BadRequest());
            }

            _context.Entry(evaluacion).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!EvaluacionExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Beispiel #3
0
        /* private async Task<Profesores> GetProfesorCompleteData(int id)
         * {
         *   return await _context.Profesores.Include(profesor => profesor.Cursos)
         *       .Include(profesor => profesor.EstudiantesXgrupos)
         *       .Include(profesor => profesor.Estudiantes)
         *       .FirstOrDefaultAsync(x => x.Id == id);
         * }*/

        public async Task <Boolean> PostAsignaciones(Asignaciones asignacion)
        {
            _context.Asignaciones.Add(asignacion);
            await _context.SaveChangesAsync();

            return(await Task.FromResult(true));
        }
Beispiel #4
0
        /* private async Task<Profesores> GetProfesorCompleteData(int id)
         * {
         *   return await _context.Profesores.Include(profesor => profesor.Cursos)
         *       .Include(profesor => profesor.EstudiantesXgrupos)
         *       .Include(profesor => profesor.Estudiantes)
         *       .FirstOrDefaultAsync(x => x.Id == id);
         * }*/

        public async Task <Boolean> PostEvaluaciones(Evaluaciones evaluacion)
        {
            _context.Evaluaciones.Add(evaluacion);
            await _context.SaveChangesAsync();

            return(await Task.FromResult(true));
        }
Beispiel #5
0
 public async Task <Boolean> PutEstudiante(Estudiantes estudiante)
 {
     context.Add(estudiante);
     try
     {
         await context.SaveChangesAsync();
     }
     catch (DbUpdateConcurrencyException)
     {
         return(false);
     }
     new CreatedAtRouteResult("obtenerEstudiante", new { id = estudiante.Id }, estudiante);
     return(true);
 }
Beispiel #6
0
 public async Task <Boolean> PutGrupo(Grupos grupo)
 {
     context.Add(grupo);
     try
     {
         await context.SaveChangesAsync();
     }
     catch (DbUpdateConcurrencyException)
     {
         return(false);
     }
     new CreatedAtRouteResult("obtenerGrupo", new { id = grupo.Id }, grupo);
     return(true);
 }
        private async Task <Profesores> GetProfesorCompleteData(int id)
        {
            var listaCursos = _context.Cursos.Include(curso => curso.CursosGrupos)
                              .ThenInclude(cursoGrupo => cursoGrupo.IdGrupoNavigation).Where(x => x.IdProfesor == id);

            _context.RemoveRange(listaCursos);
            await _context.SaveChangesAsync();

            var listaAsignaciones = _context.Asignaciones.Include(z => z.NotificacionesCorreo).Where(x => x.Profesor == id).ToList();

            foreach (Asignaciones asignacion in listaAsignaciones)
            {
                await DeleteAsignacionesP(asignacion);
            }
            _context.RemoveRange(listaAsignaciones);
            await _context.SaveChangesAsync();

            var listaGrupos = _context.Grupos.Include(EG => EG.EstudiantesXgrupos)
                              .Where(x => x.IdProfesor == id);

            _context.RemoveRange(listaGrupos);
            await _context.SaveChangesAsync();

            return(await _context.Profesores.Include(z => z.Estudiantes)
                   .FirstOrDefaultAsync(x => x.Id == id));
        }
        public async Task <IActionResult> PutEstudiantes(Estudiantes estudiantes)
        {
            try
            {
                Profesores profesor = await ComprobacionSesion.ComprobarInicioSesion(HttpContext.Request.Headers, _context);

                if (profesor == null)
                {
                    return(BadRequest());
                }
                _context.Entry(estudiantes).State = EntityState.Modified;

                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                return(BadRequest());
            }

            return(NoContent());
        }
        public async Task <IActionResult> PutProfesores(int id, Profesores profesores)
        {
            Profesores profesor = await ComprobacionSesion.ComprobarInicioSesion(HttpContext.Request.Headers, _context);

            if (profesor == null && profesor.Administrador)
            {
                return(BadRequest());
            }

            if (id != profesores.Id)
            {
                return(BadRequest());
            }

            if (profesor.Id == profesores.Id)
            {
                // Se realiza de esta manera, ya que habría conflicto con la entidad entrante (son iguales),
                // por lo que se modifica la ultima retornada por el ef
                profesor.Cedula          = profesores.Cedula;
                profesor.Nombre          = profesores.Nombre;
                profesor.PrimerApellido  = profesores.PrimerApellido;
                profesor.SegundoApellido = profesores.SegundoApellido;
                profesor.Correo          = profesores.Correo;
                profesor.Contrasenia     = profesores.Contrasenia;

                _context.Entry(profesor).State = EntityState.Modified;
            }
            else
            {
                _context.Entry(profesores).State = EntityState.Modified;
            }

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ProfesoresExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Beispiel #10
0
        public async Task <Boolean> DeleteEstudianteXGrupos(int idEstudiante, Grupos grupo)
        {
            var grupos = context.EstudiantesXgrupos.Where(x => x.IdEstudiante == idEstudiante && x.IdGrupo == grupo.Id)
                         .FirstOrDefault();

            if (grupos == null)
            {
                return(false);
            }
            try
            {
                context.EstudiantesXgrupos.Remove(grupos);
                await context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                return(false);
            }
            return(true);
        }
        private async void VerificarNotificaciones(object objetc)
        {
            using (var scope = serviceProvider.CreateScope())
            {
                BDSAEEContext context = scope.ServiceProvider.GetRequiredService <BDSAEEContext>();
                List <NotificacionesCorreo> notificaciones =
                    await context.NotificacionesCorreo.Include(n => n.IdAsignacionNavigation).ToListAsync();

                DateTime   fechaAsignacion;
                int        diasAnticipacion;
                Profesores profesor;
                Cursos     curso;
                Grupos     grupo;
                foreach (NotificacionesCorreo notificacion in notificaciones)
                {
                    fechaAsignacion  = notificacion.IdAsignacionNavigation.Fecha;
                    diasAnticipacion = notificacion.DiasAnticipacion;
                    if (fechaAsignacion.AddDays(diasAnticipacion * -1).Date.Equals(DateTime.Today.Date))
                    {
                        profesor = await context.Profesores.FindAsync(notificacion.IdAsignacionNavigation.Profesor);

                        grupo = await context.Grupos.FindAsync(notificacion.IdAsignacionNavigation.Grupo);

                        curso = await context.Cursos.FindAsync(notificacion.IdAsignacionNavigation.Curso);

                        new CorreoElectronico(notificacion.IdAsignacionNavigation, profesor, curso, grupo).Enviar();
                        context.Remove(notificacion);
                        try
                        {
                            await context.SaveChangesAsync();
                        }
                        catch (Exception)
                        {
                            //Manejar el error
                        }
                    }
                }
            }
        }