private List <User> ReadUsers(IDataReader reader) { var result = new List <User>(); var houseDA = new HouseDataAdapter(); var roleDA = new RoleDataAdapter(); while (reader.Read()) { var user = new User { Id = reader["Id"].ToString(), Email = reader["Email"]?.ToString() ?? "", Phone = reader["Phone"]?.ToString() ?? "", Password = reader["Password"].ToString(), Username = reader["Username"].ToString(), Role = new Role { Id = reader["RoleId"].ToString(), }, Status = reader["Status"]?.ToString() ?? "", House = new House { Id = reader["HouseId"].ToString() } }; if (reader["HouseId"] != null && !string.IsNullOrEmpty(reader["HouseId"].ToString())) { user.House = houseDA.GetById(user.House.Id); } user.Role = roleDA.GetById(user.Role.Id); result.Add(user); } return(result); }
private List <MoneySource> Read(IDataReader reader) { var list = new List <MoneySource>(); var houseDA = new HouseDataAdapter(); var userDA = new UserDataAdapter(); while (reader.Read()) { var item = new MoneySource { Id = reader["Id"].ToString(), Name = reader["Name"].ToString(), BalanceUSD = Convert.ToSingle(reader["BalanceUSD"]), BalanceVND = Convert.ToSingle(reader["BalanceVND"]), Owner = new User { Id = reader["OwnerId"].ToString() } }; var houseId = reader["HouseId"].ToString(); if (!string.IsNullOrEmpty(houseId)) { item.House = houseDA.GetById(houseId); } item.Owner = userDA.GetById(item.Owner.Id); list.Add(item); } return(list); }