public List <ActividadEntity> ActividadPorPersonaId(int idPersona) { try { List <ActividadEntity> actividades = new List <ActividadEntity>(); using (SqlConnection conexion = ConexionDA.ObtenerConexion()) { using (SqlCommand comando = new SqlCommand("[ActividadPorPersonaId]", conexion)) { comando.CommandType = CommandType.StoredProcedure; SqlCommandBuilder.DeriveParameters(comando); comando.Parameters["@idPersona"].Value = idPersona; using (SqlDataReader cursor = comando.ExecuteReader()) { while (cursor.Read()) { ActividadEntity auxActi = CrearActividad(cursor); auxActi.listPersonas = PersonaPorActividadId(auxActi.idActividad); actividades.Add(auxActi); } cursor.Close(); } } conexion.Close(); } return(actividades); } catch (Exception ex) { throw new ExcepcionDA("Se produjo un error al buscar por email y contraseña.", ex); } }
public List <ActividadEntity> ActividadGetAll(char tipoPersona = 'P') { try { List <ActividadEntity> actividades = new List <ActividadEntity>(); using (SqlConnection conexion = ConexionDA.ObtenerConexion()) { using (SqlCommand comando = new SqlCommand("[ActividadTraerTodos]", conexion)) { comando.CommandType = CommandType.StoredProcedure; SqlCommandBuilder.DeriveParameters(comando); using (SqlDataReader cursor = comando.ExecuteReader()) { while (cursor.Read()) { ActividadEntity auxActi = CrearActividad(cursor); auxActi.cantSocios = getTotalPersonaPorActividad(auxActi.idActividad, 'S'); auxActi.listPersonas = PersonaPorActividadId(auxActi.idActividad, tipoPersona); actividades.Add(auxActi); } cursor.Close(); } } conexion.Close(); } return(actividades); } catch (Exception ex) { throw new ExcepcionDA("Se produjo un error al buscar por email y contraseña.", ex); } }
public List <ActividadEntity> ListarActividades() { try { List <ActividadEntity> actividad = new List <ActividadEntity>(); using (SqlConnection conexion = ConexionDA.ObtenerConexion()) { using (SqlCommand comando = new SqlCommand("ActividadTraerTodos", conexion)) { comando.CommandType = CommandType.StoredProcedure; SqlCommandBuilder.DeriveParameters(comando); using (SqlDataReader cursor = comando.ExecuteReader()) { while (cursor.Read()) { actividad.Add(CrearActividad(cursor)); } cursor.Close(); } } conexion.Close(); } return(actividad); } catch (Exception ex) { throw new ExcepcionDA("Se produjo un error al buscar por email y contraseña.", ex); } }
public List <int> BuscarActividadPersonaPorId(int idPersona) { try { List <int> empleadoActividad = new List <int>(); using (SqlConnection conexion = ConexionDA.ObtenerConexion()) { using (SqlCommand comando = new SqlCommand("[ActividadPersonaGetList]", conexion)) { comando.CommandType = CommandType.StoredProcedure; SqlCommandBuilder.DeriveParameters(comando); comando.Parameters["@idPersona"].Value = idPersona; using (SqlDataReader cursor = comando.ExecuteReader()) { while (cursor.Read()) { empleadoActividad.Add(cursor.GetInt32(cursor.GetOrdinal("idActividad"))); } cursor.Close(); } } conexion.Close(); } return(empleadoActividad); } catch (Exception ex) { throw new ExcepcionDA("Se produjo un error al buscar por email y contraseña.", ex); } }
public void Actualizar(int id, string nombreArchivo, byte[] archivoFoto) { try { FileInfo infoArchivo = new FileInfo(nombreArchivo); string rutaFotos = ConfigurationManager.AppSettings["RutaFotos"]; string nuevoNombreArchivo = id.ToString() + infoArchivo.Extension; using (FileStream archivo = File.Create(rutaFotos + nuevoNombreArchivo)) { archivo.Write(archivoFoto, 0, archivoFoto.Length); archivo.Close(); } using (SqlConnection conexion = ConexionDA.ObtenerConexion()) { using (SqlCommand comando = new SqlCommand("PersonaActualizarFoto", conexion)) { comando.CommandType = CommandType.StoredProcedure; SqlCommandBuilder.DeriveParameters(comando); comando.Parameters["@idpersona"].Value = id; comando.Parameters["@Foto"].Value = nuevoNombreArchivo; comando.ExecuteNonQuery(); } conexion.Close(); } } catch (Exception ex) { throw new ExcepcionDA("Se produjo un error al actualizar la foto.", ex); } }
public void Insertar(EmpleadoEntity empleado) { try { using (SqlConnection conexion = ConexionDA.ObtenerConexion()) { using (SqlCommand comando = new SqlCommand("EmpleadoInsert", conexion)) { comando.CommandType = CommandType.StoredProcedure; SqlCommandBuilder.DeriveParameters(comando); comando.Parameters["@Dni"].Value = empleado.dni; comando.Parameters["@Nombre"].Value = empleado.Nombre.Trim(); comando.Parameters["@Apellido"].Value = empleado.Apellido.Trim(); comando.Parameters["@Telefono"].Value = empleado.Telefono; comando.Parameters["@Email"].Value = empleado.Email.Trim(); comando.Parameters["@Password"].Value = empleado.Password.Trim(); comando.Parameters["@FechaNacimiento"].Value = empleado.FechaNacimiento; comando.Parameters["@Sexo"].Value = empleado.Sexo; comando.Parameters["@TipoPersona"].Value = empleado.tipoPersona; comando.Parameters["@TipoEmpleado"].Value = empleado.tipoEmpleado; comando.Parameters["@fechaDeIngreso"].Value = empleado.fechaIngreso; comando.Parameters["@fechaDeEgreso"].Value = empleado.fechaEgreso; comando.Parameters["@ListActividad"].Value = empleado.actividad; comando.ExecuteNonQuery(); } conexion.Close(); } } catch (Exception ex) { throw new ExcepcionDA("Se produjo un error al insertar el usuario.", ex); } }
public EmpleadoEntity BuscarEmpleado(int idPersona) { try { EmpleadoEntity empleado = null; using (SqlConnection conexion = ConexionDA.ObtenerConexion()) { using (SqlCommand comando = new SqlCommand("EmpleadoBuscarPorId", conexion)) { comando.CommandType = CommandType.StoredProcedure; SqlCommandBuilder.DeriveParameters(comando); comando.Parameters["@idPersona"].Value = idPersona; int i = 0; using (SqlDataReader cursor = comando.ExecuteReader()) { if (cursor.Read()) { empleado = CrearEmpleado(cursor); i++; } cursor.Close(); } } conexion.Close(); } return(empleado); } catch (Exception ex) { throw new ExcepcionDA("Se produjo un error al buscar por ID.", ex); } }
public bool ExisteEmail(string email) { try { bool existeEmail; using (SqlConnection conexion = ConexionDA.ObtenerConexion()) { using (SqlCommand comando = new SqlCommand("PersonaExisteEmail", conexion)) { comando.CommandType = CommandType.StoredProcedure; SqlCommandBuilder.DeriveParameters(comando); comando.Parameters["@Email"].Value = email.Trim(); existeEmail = Convert.ToBoolean(comando.ExecuteScalar()); } conexion.Close(); } return(existeEmail); } catch (Exception ex) { throw new ExcepcionDA("Se produjo un error al buscar por email.", ex); } }
public void ActualizarEstadoSocio(int idSocio, int estadoNuevo) { try { using (SqlConnection conexion = ConexionDA.ObtenerConexion()) { using (SqlCommand comando = new SqlCommand("SocioActualizarEstado", conexion)) { comando.CommandType = CommandType.StoredProcedure; SqlCommandBuilder.DeriveParameters(comando); comando.Parameters["@idPersona"].Value = idSocio; comando.Parameters["@idEstado"].Value = estadoNuevo; comando.ExecuteNonQuery(); conexion.Close(); } } } catch (Exception ex) { throw new ExcepcionDA("Se produjo un error al actualizar es estado.", ex); } }
public void EliminarEmpleado(int idEmpleado) { try { using (SqlConnection conexion = ConexionDA.ObtenerConexion()) { using (SqlCommand comando = new SqlCommand("EmpleadoBorrar", conexion)) { comando.CommandType = CommandType.StoredProcedure; SqlCommandBuilder.DeriveParameters(comando); comando.Parameters["@idEmpleado"].Value = idEmpleado; comando.ExecuteNonQuery(); } conexion.Close(); } } catch (Exception ex) { throw new ExcepcionDA("Se produjo un error al eliminar Empleado.", ex); } }
public UsuarioEntity BuscarUsuario(string email, string password) { try { UsuarioEntity usuario = null; using (SqlConnection conexion = ConexionDA.ObtenerConexion()) { using (SqlCommand comando = new SqlCommand("UsuarioBuscarPorEmailPassword", conexion)) { comando.CommandType = CommandType.StoredProcedure; SqlCommandBuilder.DeriveParameters(comando); comando.Parameters["@UsuarioEmail"].Value = email.Trim(); comando.Parameters["@UsuarioPassword"].Value = password.Trim(); using (SqlDataReader cursor = comando.ExecuteReader()) { if (cursor.Read()) { usuario = CrearUsuario(cursor); } cursor.Close(); } } conexion.Close(); } return(usuario); } catch (Exception ex) { throw new ExcepcionDA("Se produjo un error al buscar por email y contraseña.", ex); } }
public GenericEntity GetListParaAdmin() { try { GenericEntity generic = new GenericEntity(); using (SqlConnection conexion = ConexionDA.ObtenerConexion()) { using (SqlCommand comando = new SqlCommand("[ListaTotalParaAdmin]", conexion)) { comando.CommandType = CommandType.StoredProcedure; SqlCommandBuilder.DeriveParameters(comando); using (SqlDataReader cursor = comando.ExecuteReader()) { while (cursor.Read()) { generic.Salas = cursor.GetInt32(cursor.GetOrdinal("Salas")); generic.Profesores = cursor.GetInt32(cursor.GetOrdinal("Profesores"));; generic.Actividades = cursor.GetInt32(cursor.GetOrdinal("Actividades"));; generic.Socios = cursor.GetInt32(cursor.GetOrdinal("Socios"));; generic.Adminitradores = cursor.GetInt32(cursor.GetOrdinal("Administradores"));; // actividad.Add(CrearActividad(cursor)); } cursor.Close(); } } conexion.Close(); } return(generic); } catch (Exception ex) { throw new ExcepcionDA("Se produjo un error al ListaTotalParaAdmin", ex); } }
public void ActualizarSocio(SocioEntity socio) { try { using (SqlConnection conexion = ConexionDA.ObtenerConexion()) { using (SqlCommand comando = new SqlCommand("SocioActualizarTodo", conexion)) { comando.CommandType = CommandType.StoredProcedure; SqlCommandBuilder.DeriveParameters(comando); comando.Parameters["@idPersona"].Value = socio.Id; comando.Parameters["@Dni"].Value = socio.dni; comando.Parameters["@Nombre"].Value = socio.Nombre.Trim(); comando.Parameters["@Apellido"].Value = socio.Apellido.Trim(); comando.Parameters["@Telefono"].Value = socio.Telefono; comando.Parameters["@Email"].Value = socio.Email.Trim(); comando.Parameters["@Password"].Value = socio.Password.Trim(); comando.Parameters["@FechaNacimiento"].Value = socio.FechaNacimiento.Date.ToString("yyyy-MM-dd"); comando.Parameters["@Sexo"].Value = socio.Sexo; comando.Parameters["@TipoPersona"].Value = socio.tipoPersona; //comando.Parameters["@FechaRegistracion"].Value = socio.FechaRegistracion?.Date.ToString("yyyy-MM-dd HH:mm:ss"); //comando.Parameters["@FechaActualizacion"].Value = socio.FechaActualizacion?.Date.ToString("yyyy-MM-dd HH:mm:ss"); //comando.Parameters["@NroTarjetaIdentificacion"].Value = socio.NroTarjetaIdentificacion; comando.Parameters["@idEstado"].Value = socio.IdEstado; comando.Parameters["@ListActividad"].Value = socio.actividad; comando.ExecuteNonQuery(); conexion.Close(); } } } catch (Exception ex) { throw new ExcepcionDA("Se produjo un error al actualizar el socio.", ex); } }
public SocioEntity InsertarSocio(PersonaEntity socio) { try { SqlCommand comando = null; using (SqlConnection conexion = ConexionDA.ObtenerConexion()) { using (comando = new SqlCommand("SocioInsert", conexion)) { comando = personaDA.InsertarPersona(socio, comando, conexion); comando.Parameters["@NroTarjetaIdentificacion"].Value = socio.dni.Trim(); comando.Parameters["@idEstado"].Value = 2; comando.ExecuteNonQuery(); socio.Id = Convert.ToInt32(comando.Parameters["@RETURN_VALUE"].Value); return((SocioEntity)socio); } } } catch (Exception ex) { throw new ExcepcionDA("Se produjo un error al buscar por email y contraseña.", ex); } }
public SalaEntity BuscarSala(String nombre) { SalaEntity salaEntity = null; try { using (SqlConnection conexion = ConexionDA.ObtenerConexion()) { using (SqlCommand comando = new SqlCommand("SalaBuscarPorNombre", conexion)) { comando.CommandType = CommandType.StoredProcedure; SqlCommandBuilder.DeriveParameters(comando); comando.Parameters["@nombre"].Value = nombre.Trim(); using (SqlDataReader cursor = comando.ExecuteReader()) { if (cursor.Read()) { if (salaEntity == null) { salaEntity = new SalaEntity(); } salaEntity = CrearSala(cursor); } cursor.Close(); } } conexion.Close(); } } catch (Exception ex) { throw new ExcepcionDA("Se produjo un error al buscar sala por nombre.", ex); } return(salaEntity); }