override public Identidad getById(int idIdentidad) { //Elementos de la identidad a devolver Identidad identidad = null; String tipoIdentidad = ""; String nombre = ""; String apellido = ""; String tipoDocumento = ""; String numeroDocumento = ""; String mail = ""; DateTime fechaNacimiento = Utils.getSystemDatetimeNow(); String nacionalidad = ""; String telefono = ""; List <Direccion> direcciones = new List <Direccion>(); RepositorioDireccion repoDireccion = new RepositorioDireccion(); //Configuraciones de la consulta String connectionString = ConfigurationManager.AppSettings["BaseLocal"]; SqlConnection sqlConnection = new SqlConnection(connectionString); SqlCommand sqlCommand = new SqlCommand(); SqlDataReader reader; //Primera Consulta sqlCommand.Parameters.AddWithValue("@idIdentidad", idIdentidad); sqlCommand.CommandType = CommandType.Text; sqlCommand.Connection = sqlConnection; sqlCommand.CommandText = "SELECT * FROM LOS_BORBOTONES.Identidad WHERE idIdentidad = @idIdentidad"; sqlConnection.Open(); reader = sqlCommand.ExecuteReader(); while (reader.Read()) { nombre = reader.GetString(reader.GetOrdinal("Nombre")); apellido = reader.SafeGetString(reader.GetOrdinal("Apellido")); tipoIdentidad = reader.GetString(reader.GetOrdinal("TipoIdentidad")); tipoDocumento = reader.GetString(reader.GetOrdinal("TipoDocumento")); numeroDocumento = reader.GetString(reader.GetOrdinal("NumeroDocumento")); mail = reader.GetString(reader.GetOrdinal("Mail")); nacionalidad = reader.SafeGetString(reader.GetOrdinal("Nacionalidad")); telefono = reader.GetString(reader.GetOrdinal("Telefono")); fechaNacimiento = reader.SafeGetDateTime(reader.GetOrdinal("FechaNacimiento")); direcciones.Add(repoDireccion.getByIdIdentidad(idIdentidad)); } //Cierro Primera Consulta sqlConnection.Close(); //Si no encuentro elemento con ese ID tiro una excepción if (nombre.Equals("")) { throw new NoExisteIDException("No existe identidad con el ID asociado"); } //Armo la identidad identidad = new Identidad(idIdentidad, tipoIdentidad, nombre, apellido, tipoDocumento, numeroDocumento, mail, fechaNacimiento, nacionalidad, telefono, direcciones); return(identidad); }
public override Hotel getById(int id) { RepositorioCategoria repositorioCategoria = new RepositorioCategoria(); RepositorioRegimen repositorioRegimen = new RepositorioRegimen(); RepositorioCierreTemporal repositorioCierreTemporal = new RepositorioCierreTemporal(); RepositorioDireccion repositorioDireccion = new RepositorioDireccion(); RepositorioReserva repositorioReserva = new RepositorioReserva(); String connectionString = ConfigurationManager.AppSettings["BaseLocal"]; SqlConnection sqlConnection = new SqlConnection(connectionString); SqlCommand sqlCommand = new SqlCommand(); SqlDataReader reader; Hotel hotel = null; sqlCommand.Parameters.AddWithValue("@idHotel", id); sqlCommand.CommandType = CommandType.Text; sqlCommand.Connection = sqlConnection; sqlCommand.CommandText = "SELECT * FROM LOS_BORBOTONES.Hotel WHERE idHotel = @idHotel"; sqlConnection.Open(); reader = sqlCommand.ExecuteReader(); if (reader.Read()) { int idHotel = reader.GetInt32(reader.GetOrdinal("idHotel")); String nombre = reader.GetString(reader.GetOrdinal("Nombre")); String mail = reader.SafeGetString(reader.GetOrdinal("Mail")); String telefono = reader.SafeGetString(reader.GetOrdinal("Telefono")); DateTime fechaInicio = reader.GetDateTime(reader.GetOrdinal("FechaInicioActividades")); int idCategoria = reader.GetInt32(reader.GetOrdinal("idCategoria")); int idDireccion = reader.GetInt32(reader.GetOrdinal("idDireccion")); Categoria categoria = repositorioCategoria.getById(idCategoria); Direccion direccion = repositorioDireccion.getById(idDireccion); hotel = new Hotel(idHotel, categoria, direccion, nombre, mail, telefono, fechaInicio); } else { //Si no encuentro elemento con ese ID tiro una excepción throw new NoExisteIDException("No existe hotel con el ID asociado"); } //Cierro Primera Consulta sqlConnection.Close(); return(hotel); }
public override List <Hotel> getAll() { RepositorioCategoria repositorioCategoria = new RepositorioCategoria(); RepositorioRegimen repositorioRegimen = new RepositorioRegimen(); RepositorioCierreTemporal repositorioCierreTemporal = new RepositorioCierreTemporal(); RepositorioDireccion repositorioDireccion = new RepositorioDireccion(); RepositorioReserva repositorioReserva = new RepositorioReserva(); List <Hotel> hoteles = new List <Hotel>(); String connectionString = ConfigurationManager.AppSettings["BaseLocal"]; SqlConnection sqlConnection = new SqlConnection(connectionString); SqlCommand sqlCommand = new SqlCommand(); SqlDataReader reader; Hotel hotel = null; sqlCommand.CommandType = CommandType.Text; sqlCommand.Connection = sqlConnection; sqlCommand.CommandText = "SELECT idHotel,Nombre,Mail,Telefono,FechaInicioActividades,idCategoria,idDireccion FROM LOS_BORBOTONES.Hotel AS HOT;"; sqlConnection.Open(); reader = sqlCommand.ExecuteReader(); while (reader.Read()) { int idHotel = reader.GetInt32(reader.GetOrdinal("idHotel")); String nombre = reader.GetString(reader.GetOrdinal("Nombre")); String mail = reader.SafeGetString(reader.GetOrdinal("Mail")); String telefono = reader.SafeGetString(reader.GetOrdinal("Telefono")); DateTime fechaInicio = reader.GetDateTime(reader.GetOrdinal("FechaInicioActividades")); int idCategoria = reader.GetInt32(reader.GetOrdinal("idCategoria")); int idDireccion = reader.GetInt32(reader.GetOrdinal("idDireccion")); Categoria categoria = repositorioCategoria.getById(idCategoria); Direccion direccion = repositorioDireccion.getById(idDireccion); hotel = new Hotel(idHotel, categoria, direccion, nombre, mail, telefono, fechaInicio); hoteles.Add(hotel); } //Cierro Primera Consulta sqlConnection.Close(); return(hoteles); }
public List <Hotel> getByQuery(String nombreHotel, int?estrellas, String ciudad, String pais) { RepositorioCategoria repositorioCategoria = new RepositorioCategoria(); RepositorioRegimen repositorioRegimen = new RepositorioRegimen(); RepositorioCierreTemporal repositorioCierreTemporal = new RepositorioCierreTemporal(); RepositorioDireccion repositorioDireccion = new RepositorioDireccion(); RepositorioReserva repositorioReserva = new RepositorioReserva(); List <Hotel> hoteles = new List <Hotel>(); String connectionString = ConfigurationManager.AppSettings["BaseLocal"]; SqlConnection sqlConnection = new SqlConnection(connectionString); SqlCommand sqlCommand = new SqlCommand(); SqlDataReader reader; sqlCommand.CommandType = CommandType.Text; sqlCommand.Connection = sqlConnection; sqlCommand.CommandText = "SELECT DISTINCT(HOT.idHotel),HOT.Nombre,HOT.Mail,HOT.Telefono,HOT.FechaInicioActividades,HOT.idCategoria,HOT.idDireccion FROM LOS_BORBOTONES.Hotel AS HOT" + " JOIN LOS_BORBOTONES.Categoria AS CAT ON CAT.idCategoria= HOT.idCategoria" + " JOIN LOS_BORBOTONES.Direccion AS DIR ON DIR.idDireccion = HOT.idDireccion" + getCondiciones(nombreHotel, estrellas, ciudad, pais, sqlCommand) + ";"; sqlConnection.Open(); reader = sqlCommand.ExecuteReader(); while (reader.Read()) { int idHotel = reader.GetInt32(reader.GetOrdinal("idHotel")); String nombre = reader.GetString(reader.GetOrdinal("Nombre")); String mail = reader.SafeGetString(reader.GetOrdinal("Mail")); String telefono = reader.SafeGetString(reader.GetOrdinal("Telefono")); DateTime fechaInicio = reader.GetDateTime(reader.GetOrdinal("FechaInicioActividades")); int idCategoria = reader.GetInt32(reader.GetOrdinal("idCategoria")); int idDireccion = reader.GetInt32(reader.GetOrdinal("idDireccion")); Categoria categoria = repositorioCategoria.getById(idCategoria); Direccion direccion = repositorioDireccion.getById(idDireccion); Hotel hotel = new Hotel(idHotel, categoria, direccion, nombre, mail, telefono, fechaInicio); hoteles.Add(hotel); } //Cierro Primera Consulta sqlConnection.Close(); return(hoteles); }
override public int create(Cliente cliente) { int idCliente = 0; RepositorioIdentidad repoIdentidad = new RepositorioIdentidad(); if (this.exists(cliente) || repoIdentidad.exists(cliente.getIdentidad())) { throw new ElementoYaExisteException("Ya existe un cliente o un usuario con el mismo documento o el mismo mail."); } else { //llamo a crear la identidad y traigo el IdIdentidad int idIdentidad = repoIdentidad.create(cliente.getIdentidad()); //llamo a crear la direccion y traigo el IdDireccion, le seteo el idIdentidad que lo necesita cliente.getIdentidad().getDireccion().setIdIdentidad(idIdentidad); RepositorioDireccion repoDireccion = new RepositorioDireccion(); int idDireccion = repoDireccion.create(cliente.getIdentidad().getDireccion()); //ahora ya tengo todo para crear el cliente String connectionString = ConfigurationManager.AppSettings["BaseLocal"]; SqlConnection sqlConnection = new SqlConnection(connectionString); SqlCommand sqlCommand = new SqlCommand(); SqlDataReader reader; sqlCommand.CommandType = CommandType.Text; sqlCommand.Connection = sqlConnection; sqlCommand.Parameters.AddWithValue("@Activo", cliente.getActivo()); sqlCommand.Parameters.AddWithValue("@idIdentidad", idIdentidad); StringBuilder sqlBuilder = new StringBuilder(); sqlBuilder.Append(@" BEGIN TRY BEGIN TRANSACTION INSERT INTO LOS_BORBOTONES.Cliente(Activo,idIdentidad) OUTPUT INSERTED.idCliente VALUES(@Activo,@idIdentidad); DECLARE @idCliente int; SET @idCliente = SCOPE_IDENTITY(); "); sqlBuilder.Append(@" COMMIT END TRY BEGIN CATCH ROLLBACK END CATCH "); sqlCommand.CommandText = sqlBuilder.ToString(); sqlConnection.Open(); reader = sqlCommand.ExecuteReader(); if (reader.Read()) { idCliente = reader.GetInt32(reader.GetOrdinal("idCliente")); } sqlConnection.Close(); } return(idCliente); }
override public int create(Usuario usuario) { int idUsuario = 0; RepositorioIdentidad repoIdentidad = new RepositorioIdentidad(); if (this.exists(usuario) || repoIdentidad.exists(usuario.getIdentidad())) { throw new ElementoYaExisteException("Ya existe un usuario con el mismo nombre, o su Mail/Tipo y Numero de documento está repetido."); } else { //llamo a crear la identidad y traigo el IdIdentidad //RepositorioIdentidad repoIdentidad = new RepositorioIdentidad(); int idIdentidad = repoIdentidad.create(usuario.getIdentidad()); //llamo a crear la direccion y traigo el IdDireccion, le seteo el idIdentidad que lo necesita usuario.getIdentidad().getDireccion().setIdIdentidad(idIdentidad); RepositorioDireccion repoDireccion = new RepositorioDireccion(); int idDireccion = repoDireccion.create(usuario.getIdentidad().getDireccion()); //ahora ya tengo todo para crear el usuario String connectionString = ConfigurationManager.AppSettings["BaseLocal"]; SqlConnection sqlConnection = new SqlConnection(connectionString); SqlCommand sqlCommand = new SqlCommand(); SqlDataReader reader; //encripto clave string passwordEncriptada = this.EncriptarSHA256(usuario.getPassword()); sqlCommand.CommandType = CommandType.Text; sqlCommand.Connection = sqlConnection; sqlCommand.Parameters.AddWithValue("@Username", usuario.getUsername()); sqlCommand.Parameters.AddWithValue("@Activo", usuario.getActivo()); sqlCommand.Parameters.AddWithValue("@Password", passwordEncriptada); sqlCommand.Parameters.AddWithValue("@IntentosFallidosLogin", usuario.getIntentosFallidosLogin()); sqlCommand.Parameters.AddWithValue("@idIdentidad", idIdentidad); StringBuilder sqlBuilder = new StringBuilder(); sqlBuilder.Append(@" BEGIN TRY BEGIN TRANSACTION INSERT INTO LOS_BORBOTONES.Usuario(Username,Password,IntentosFallidosLogin,Activo,idIdentidad) OUTPUT INSERTED.idUsuario VALUES(@Username,@Password,@IntentosFallidosLogin,@Activo,@idIdentidad); DECLARE @idUsuario int; SET @idUsuario = SCOPE_IDENTITY(); "); //AGREGO DINAMICAMENTE LOS ROLES A LA CONSULTA int i = 1; foreach (Rol r in usuario.getRoles()) { String paramName = "@idRol" + i.ToString(); sqlBuilder.AppendFormat("INSERT INTO LOS_BORBOTONES.Rol_X_Usuario(idRol,idUsuario) VALUES ({0}, @idUsuario)", paramName); sqlCommand.Parameters.AddWithValue(paramName, r.getIdRol()); i++; } //AGREGO DINAMICAMENTE LOS HOTELES A LA CONSULTA int k = 1; foreach (Hotel h in usuario.getHoteles()) { String paramName = "@idHotel" + k.ToString(); sqlBuilder.AppendFormat("INSERT INTO LOS_BORBOTONES.Hotel_X_Usuario(idHotel,idUsuario) VALUES ({0}, @idUsuario)", paramName); sqlCommand.Parameters.AddWithValue(paramName, h.getIdHotel()); k++; } sqlBuilder.Append(@" COMMIT END TRY BEGIN CATCH ROLLBACK END CATCH "); sqlCommand.CommandText = sqlBuilder.ToString(); sqlConnection.Open(); reader = sqlCommand.ExecuteReader(); if (reader.Read()) { idUsuario = reader.GetInt32(reader.GetOrdinal("idUsuario")); } sqlConnection.Close(); } return(idUsuario); }