/// <summary> /// Obtiene la ubicacion de la base de datos /// </summary> /// <param name="id"></param> /// <returns></returns> public static Location Obtener(Guid id) { Location res = new Location(); SqlCommand cmd = null; SqlDataReader dr = null; string query = @"SELECT idUbicacion, latitud, longitud, FROM Ubicacion WHERE idUbicacion = @id"; try { cmd = OperationsSql.CreateBasicCommand(query); cmd.Parameters.AddWithValue("@id", id); dr = OperationsSql.ExecuteDataReaderCommand(cmd); while (dr.Read()) { res = new Location() { IdLocation = dr.GetGuid(0), Latitude = dr.GetInt32(1), Length = dr.GetInt32(2) }; } } catch (Exception ex) { OperationsLogs.WriteLogsRelease("LocationDal", "Obtener(Get)", string.Format("{0} {1} Error: {1}", DateTime.Now.ToString(), DateTime.Now.ToString(), ex.Message)); throw ex; } finally { cmd.Connection.Close(); } return(res); }
public static User ObtenerIdUsuario(string nombreUsuario) { User res = new User(); SqlCommand cmd = null; SqlDataReader dr = null; string query = @"SELECT idUsuario FROM Usuario WHERE nombre = @nombre and eliminado = 1"; try { cmd = OperationsSql.CreateBasicCommand(query); cmd.Parameters.AddWithValue("@nombre", nombreUsuario); dr = OperationsSql.ExecuteDataReaderCommand(cmd); while (dr.Read()) { res = new User() { IdUser = dr.GetGuid(0) }; } } catch (Exception ex) { OperationsLogs.WriteLogsRelease("UsuarioDal", "ObtenerIdUsuario(Get)", string.Format("{0} {1} Error: {1}", DateTime.Now.ToString(), DateTime.Now.ToString(), ex.Message)); throw ex; } finally { cmd.Connection.Close(); } return(res); }
/// <summary> /// Obtiene un Persona de la base de datos /// </summary> /// <param name="id"></param> /// <returns></returns> public static Client ObtenerCliente(Guid id) { Client persona = new Client(); SqlCommand cmd = null; SqlDataReader dr = null; string query = @"SELECT idPersona, idUsuario cedulaDeIdentidad, nombres, primerApellido, segundoApellido, correoElectronico, direccion, telefono, eliminado FROM Persona WHERE idPersona = @id and eliminado = 1"; try { cmd = OperationsSql.CreateBasicCommand(query); cmd.Parameters.AddWithValue("@id", id); dr = OperationsSql.ExecuteDataReaderCommand(cmd); while (dr.Read()) { persona = new Client() { IdPerson = dr.GetGuid(0), User = UserDal.Obtener(dr.GetGuid(1)), IdentityCard = dr.GetString(2), Names = dr.GetString(3), FirstSurname = dr.GetString(4), SecondSurname = dr.GetString(5), Email = dr.GetString(6), Address = dr.GetString(7), Phone = dr.GetInt32(8), State = dr.GetByte(9) }; } } catch (Exception ex) { OperationsLogs.WriteLogsRelease("PersonaDal", "ObtenerCliente(Get)", string.Format("{0} Error: {1}", DateTime.Now.ToString(), ex.Message)); throw ex; } finally { cmd.Connection.Close(); } return(persona); }
public static Product Get(Guid id) { Product product = new Product(); SqlCommand cmd = null; SqlDataReader dr = null; string query = @"SELECT idProducto, imagen, nombre, ingredientes, descripcion, oferta, eliminado FROM Producto WHERE idProducto = @id AND eliminado = 1"; try { cmd = OperationsSql.CreateBasicCommand(query); cmd.Parameters.AddWithValue("@id", id); dr = OperationsSql.ExecuteDataReaderCommand(cmd); while (dr.Read()) { product = new Product { IdProduct = dr.GetGuid(0), Image = dr.GetString(1), Name = dr.GetString(2), Ingredients = dr.GetString(3), Description = dr.GetString(4), Offer = dr.GetByte(5), Price = dr.GetSqlMoney(6) }; } } catch (Exception ex) { OperationsLogs.WriteLogsRelease("ProductoDal", "Obtenet(Get)", string.Format("{0} {1} Error: {1}", DateTime.Now.ToString(), DateTime.Now.ToString(), ex.Message)); throw ex; } finally { cmd.Connection.Close(); } return(product); }
/// <summary> /// Metodo para obtener un Cliente /// </summary> /// <param name="id">Identificado del Cliente </param> /// <returns>Cliente</returns> public static Client Obtener(Guid id) { Client cliente = null; SqlCommand cmd = null; SqlDataReader dr = null; string query = @"SELECT c.idPersona, c.idUbicacion FROM Cliente c INNER JOIN Persona p ON p.idPersona = c.idPersona WHERE c.idPersona = @id and p.eliminado = 1"; try { cmd = OperationsSql.CreateBasicCommand(query); cmd.Parameters.AddWithValue("@id", id); dr = OperationsSql.ExecuteDataReaderCommand(cmd); cliente = PersonDal.ObtenerCliente(id); while (dr.Read()) { cliente.IdPerson = dr.GetGuid(0); cliente.Location = LocationDal.Obtener(dr.GetGuid(1)); } } catch (SqlException ex) { OperationsLogs.WriteLogsRelease("ClienteDal", "Obtenet", string.Format("{0} {1} Error: {1}", DateTime.Now.ToString(), DateTime.Now.ToString(), ex.Message)); throw ex; } catch (Exception ex) { OperationsLogs.WriteLogsRelease("ClienteDal", "Obtenet", string.Format("{0} {1} Error: {1}", DateTime.Now.ToString(), DateTime.Now.ToString(), ex.Message)); throw ex; } finally { cmd.Connection.Close(); } return(cliente); }
/// <summary> /// Obtiene un Usuario de la base de datos /// </summary> /// <param name="id"></param> /// <returns></returns> public static User Obtener(Guid id) { User res = new User(); SqlCommand cmd = null; SqlDataReader dr = null; string query = @"SELECT idUsuario, nombre, password, rol, eliminado FROM Usuarios WHERE idUsuario = @id and eliminado = 1"; try { cmd = OperationsSql.CreateBasicCommand(query); cmd.Parameters.AddWithValue("@id", id); dr = OperationsSql.ExecuteDataReaderCommand(cmd); while (dr.Read()) { res = new User() { IdUser = dr.GetGuid(0), UserName = dr.GetString(1), Password = dr.GetString(2), Role = dr.GetString(3), State = dr.GetByte(4) }; } } catch (Exception ex) { OperationsLogs.WriteLogsRelease("UsuarioDal", "Obtenet(Get)", string.Format("{0} {1} Error: {1}", DateTime.Now.ToString(), DateTime.Now.ToString(), ex.Message)); throw ex; } finally { cmd.Connection.Close(); } return(res); }