public static void setColegio(Entities.Colegio Colegio) { if (Colegio != null) { HttpContext.Current.Session["Colegio"] = Colegio; } }
public Entities.Colegio ObtenerxId(long id) { Entities.Colegio ColegioActual = new Entities.Colegio(); try { ColegioActual = db.Set <Entities.Colegio>().Where(x => x.ColegioId == id).FirstOrDefault(); } catch (Exception) { } return(ColegioActual); }
private string Actualizar(Entities.Colegio entidad) { string Mensaje = "OK"; string PathLogo = ConfigurationManager.AppSettings["Path_LogoApp"].ToString(); try { Entities.Colegio ColegioActual = ObtenerxId(entidad.ColegioId); if (ColegioActual.ColegioId > 0) { ColegioActual.Nombre = entidad.Nombre; ColegioActual.Direccion = entidad.Direccion; ColegioActual.Telefono = entidad.Telefono; ColegioActual.Contacto = entidad.Contacto; ColegioActual.TelefonoContacto = entidad.TelefonoContacto; ColegioActual.Alias = entidad.Alias; ColegioActual.Activo = entidad.Activo; db.SaveChanges(); if (Mensaje.Equals("OK")) { //Se crea carpeta por colegio para almacenar el logo string Path_Colegio_Logo = string.Format(@"{0}\{1}", PathLogo, entidad.ColegioId); if (!(Directory.Exists(Path_Colegio_Logo))) { Directory.CreateDirectory(Path_Colegio_Logo); } if (entidad.Fotografia != null) { ConvetirbyteImage(entidad.Fotografia.Content).Save(string.Format(@"{0}\logo.png", Path_Colegio_Logo)); } } } else { Mensaje = "El colegio seleccionado no se encuentra con ID valido"; } } catch (Exception ex) { Mensaje = string.Format("Descripción del Error {0}", ex.Message); } return(Mensaje); }
public string Guardar(Entities.Colegio entidad) { string Mensaje = "OK"; if (entidad.ColegioId > 0) { Mensaje = Actualizar(entidad); } else { Mensaje = Agregar(entidad); } return(Mensaje); }
private string Agregar(Entities.Colegio entidad) { string Mensaje = "OK"; string PathLogo = ConfigurationManager.AppSettings["Path_LogoApp"].ToString(); try { int Id = Correlativo(); if (Id > 0) { long lngColegioId = new Herramienta().Formato_Correlativo(Id); if (lngColegioId > 0) { entidad.ColegioId = lngColegioId; entidad.Correlativo = Id; entidad.Fecha = DateTime.Today; db.Set <Entities.Colegio>().Add(entidad); db.SaveChanges(); if (Mensaje.Equals("OK")) { //Se crea carpeta por colegio para almacenar el logo string Path_Colegio_Logo = string.Format(@"{0}\{1}", PathLogo, entidad.ColegioId); if (!(Directory.Exists(Path_Colegio_Logo))) { Directory.CreateDirectory(Path_Colegio_Logo); } if (entidad.Fotografia != null) { ConvetirbyteImage(entidad.Fotografia.Content).Save(string.Format(@"{0}\logo.png", Path_Colegio_Logo)); } } } } } catch (Exception ex) { Mensaje = string.Format("Descripción del Error {0}", ex.Message); } return(Mensaje); }
public static Entities.Colegio getColegio() { Entities.Colegio ColegioActual = new Entities.Colegio(); if (HttpContext.Current.Session["Colegio"] != null) { Entities.Colegio Colegio = (Entities.Colegio)HttpContext.Current.Session["Colegio"]; if (Colegio != null) { ColegioActual = Colegio; } } return(ColegioActual); }
public static long getColegioId() { long ColegioId = 0; if (HttpContext.Current.Session["Colegio"] != null) { Entities.Colegio Colegio = (Entities.Colegio)HttpContext.Current.Session["Colegio"]; if (Colegio != null) { ColegioId = Colegio.ColegioId; } } return(ColegioId); }
private int Correlativo() { int Id = 1; try { Entities.Colegio ColegioActual = db.Set <Entities.Colegio>().AsNoTracking().Where(x => x.Fecha.Year == DateTime.Today.Year && x.Fecha.Month == DateTime.Today.Month && x.Fecha.Day == DateTime.Today.Day).OrderByDescending(x => x.Correlativo).FirstOrDefault(); if (ColegioActual != null) { Id = ColegioActual.Correlativo + 1; } } catch (Exception) { } return(Id); }
public static string getColegioNombre() { string Nombre = string.Empty; if (HttpContext.Current.Session["Colegio"] != null) { Entities.Colegio Colegio = (Entities.Colegio)HttpContext.Current.Session["Colegio"]; if (Colegio != null) { Nombre = Colegio.Nombre; } } else { Nombre = "SIRIUS"; } return(Nombre); }
public ActionResult Crear(Entities.Colegio modelo, HttpPostedFileBase logoApp, bool activo) { if (logoApp != null) { modelo.Fotografia = new ColegioLogo(); if (logoApp != null) { byte[] FileData = new byte[logoApp.ContentLength + 1]; logoApp.InputStream.Read(FileData, 0, logoApp.ContentLength); modelo.Fotografia = new ColegioLogo() { Nombre = logoApp.FileName, Content = FileData, ContentType = logoApp.ContentType, Length = logoApp.ContentLength }; } } if (ModelState.IsValid) { modelo.Activo = activo; string strMensaje = new ColegioBL().Guardar(modelo); if (strMensaje.Equals("OK")) { TempData["Colegio-Success"] = strMensaje; return(RedirectToAction("Index")); } else { ModelState.AddModelError("", strMensaje); } } string strAtributo = "checked='checked'"; ViewBag.ActivoSi = activo == true ? strAtributo : ""; ViewBag.ActivoNo = activo == false ? strAtributo : ""; return(View(modelo)); }
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); }