public bool SaveUser(User user) { var ctx = HttpContext.Current; if (ctx != null) { try { var currentData = ((User[])ctx.Cache[CacheKey]).ToList(); //get a list of the current data HouseRepository tempRepo = new HouseRepository(); user.MyHouses = tempRepo.GetAllHouses(); currentData.Add(user); //add the new user Console.Write(user.UserName); Console.Write(user.MyHouses[0].HouseName); for (int i = 0; i < user.MyHouses.Count(); i++) { Console.Write(user.MyHouses[i].HouseName); } ctx.Cache[CacheKey] = currentData.ToArray(); //recache the array return(true); } catch (Exception ex) { Console.WriteLine(ex.ToString()); return(false); } } return(false); }
static void Main() { HouseRepository HouseRepo = new HouseRepository(); House[] houses = new House[] { }; houses = HouseRepo.GetAllHouses(); Console.Write(houses[0].HouseName); for (int i = 0; i < houses[0].MyRooms.Count(); i++) { Console.Write(houses[0].MyRooms[i].RoomName); } }