private string Agregar(Alumno entidad) { string Mensaje = "OK"; string Alias = string.Empty; try { //Se obtiene el alias del colegio Entities.Colegio ColegioActual = db.Set <Entities.Colegio>().AsNoTracking().Where(x => x.ColegioId == entidad.ColegioId).FirstOrDefault(); if (ColegioActual == null) { return("Se le informa que el colegio no se encuentra registrado en el sistema"); } if (string.IsNullOrWhiteSpace(ColegioActual.Alias)) { return("Se le informa que no tiene configurado el alias del colegio, por favor comunicarse con el administrador"); } Alias = ColegioActual.Alias.ToLower(); int Id = Correlativo(); if (Id > 0) { long lngAlumnoId = new Herramienta().Formato_Correlativo(Id); if (lngAlumnoId > 0) { entidad.AlumnoId = lngAlumnoId; entidad.Correlativo = Id; entidad.Fecha = DateTime.Today; entidad.Nombre = Nombre_Completo(entidad); //Se crea el alumno db.Set <Alumno>().Add(entidad); //Se verifica que no exista el usuario string LoginOriginal = string.Format("{0}.{1}.a.{2}", entidad.PrimerNombre.ToLower(), entidad.PrimerApellido.ToLower(), Alias).Replace(" ", "_"); string Login = LoginOriginal; int CantidadUsuario = db.Set <Usuario>().AsNoTracking().Where(x => x.LoginOriginal.Equals(Login)).Count(); if (CantidadUsuario > 0) { Login = string.Format("{0}.{1}.{2}.a.{3}", entidad.PrimerNombre.ToLower(), entidad.PrimerApellido.ToLower(), CantidadUsuario, Alias).Replace(" ", "_"); } //Se crea usuario del alumno Usuario UsuarioAlumno = new Usuario(); UsuarioAlumno.RelacionId = entidad.AlumnoId; UsuarioAlumno.ColegioId = entidad.ColegioId; UsuarioAlumno.RolId = 20201001001; UsuarioAlumno.LoginOriginal = LoginOriginal; UsuarioAlumno.Login = Login; UsuarioAlumno.Password = Key(Concat_Usuario(UsuarioAlumno.Login, DateTime.Today.Year.ToString())); UsuarioAlumno.Nombre = entidad.Nombre; UsuarioAlumno.Fecha = DateTime.Today; UsuarioAlumno.ReiniciarPassword = false; UsuarioAlumno.Administrador = false; UsuarioAlumno.Activo = true; int UsuarioId = CorrelativoUsuario(); if (UsuarioId == 0) { return("Se le informa que no se creo el alumno(a), por favor intente de nuevo"); } long lngUsuarioId = new Herramienta().Formato_Correlativo(UsuarioId); if (lngUsuarioId > 0) { UsuarioAlumno.UsuarioId = lngUsuarioId; UsuarioAlumno.Correlativo = UsuarioId; } db.Set <Usuario>().Add(UsuarioAlumno); db.SaveChanges(); } } } catch (Exception ex) { Mensaje = string.Format("Descripción del Error {0}", ex.Message); } return(Mensaje); }
private string Agregar(Curso entidad) { string Mensaje = "OK"; try { int Id = Correlativo(); if (Id > 0) { long lngCursoId = new Herramienta().Formato_Correlativo(Id); if (lngCursoId > 0) { entidad.CursoId = lngCursoId; entidad.Correlativo = Id; entidad.Fecha = DateTime.Today; if (entidad.Grados != null && entidad.Grados.Count() > 0) { entidad.Grados.ForEach(x => { x.CursoId = entidad.CursoId; }); } db.Set <Curso>().Add(entidad); //Se verifica que contenga nota significa que es un curso actitudinal if (entidad.Nota > 0) { int ActividadId = ActividadCorrelativo(); if (ActividadId > 0) { if (entidad.Grados != null && entidad.Grados.Count() > 0) { entidad.Grados.ForEach(x => { db.Set <Actividad>().Add(new Actividad() { ActividadId = new Herramienta().Formato_Correlativo(ActividadId), ColegioId = entidad.ColegioId, CursoId = entidad.CursoId, GradoId = x.GradoId, SeccionId = 20201001001, CicloId = entidad.CicloId, UnidadId = 20201108001, TipoId = 20201108004, Nombre = entidad.Nombre, Descripcion = entidad.Nombre, NotaMaxima = entidad.Nota, FechaEntrega = DateTime.Today, ResponsableId = entidad.ResponsableId, Fecha = DateTime.Today, Correlativo = ActividadId }); ActividadId++; db.Set <Actividad>().Add(new Actividad() { ActividadId = new Herramienta().Formato_Correlativo(ActividadId), ColegioId = entidad.ColegioId, CursoId = entidad.CursoId, GradoId = x.GradoId, SeccionId = 20201001001, CicloId = entidad.CicloId, UnidadId = 20201108002, TipoId = 20201108004, Nombre = entidad.Nombre, Descripcion = entidad.Nombre, NotaMaxima = entidad.Nota, FechaEntrega = DateTime.Today, ResponsableId = entidad.ResponsableId, Fecha = DateTime.Today, Correlativo = ActividadId }); ActividadId++; db.Set <Actividad>().Add(new Actividad() { ActividadId = new Herramienta().Formato_Correlativo(ActividadId), ColegioId = entidad.ColegioId, CursoId = entidad.CursoId, GradoId = x.GradoId, SeccionId = 20201001001, CicloId = entidad.CicloId, UnidadId = 20201108003, TipoId = 20201108004, Nombre = entidad.Nombre, Descripcion = entidad.Nombre, NotaMaxima = entidad.Nota, FechaEntrega = DateTime.Today, ResponsableId = entidad.ResponsableId, Fecha = DateTime.Today, Correlativo = ActividadId }); ActividadId++; db.Set <Actividad>().Add(new Actividad() { ActividadId = new Herramienta().Formato_Correlativo(ActividadId), ColegioId = entidad.ColegioId, CursoId = entidad.CursoId, GradoId = x.GradoId, SeccionId = 20201001001, CicloId = entidad.CicloId, UnidadId = 20201108004, TipoId = 20201108004, Nombre = entidad.Nombre, Descripcion = entidad.Nombre, NotaMaxima = entidad.Nota, FechaEntrega = DateTime.Today, ResponsableId = entidad.ResponsableId, Fecha = DateTime.Today, Correlativo = ActividadId }); ActividadId++; }); } } else { return("Se le informa que el curso actitudinal no se creo, por favor intente de nuevo"); } } db.SaveChanges(); } } } catch (Exception ex) { Mensaje = string.Format("Descripción del Error {0}", ex.Message); } return(Mensaje); }