public static List <ActiveCustomer> GetCustomerCheckoutByDate(string houseId, DateTime date) { return(SqlHelper.ExecuteReader(ConfigManager.ConnectionString, CommandType.StoredProcedure, SP_CUSTOMER_SELECT_CHECKOUT_BY_DATE, new[] { new SqlParameter("@houseId", houseId), new SqlParameter("@date", date) }, reader => { var list = new List <ActiveCustomer>(); var allRooms = RoomService.GetRooms(houseId); while (reader.Read()) { var item = new ActiveCustomer { Id = reader["Id"].ToString(), Address = reader["Address"]?.ToString() ?? "", Country = reader["Country"]?.ToString() ?? "", Email = reader["Email"]?.ToString() ?? "", Name = reader["Name"].ToString(), Phone = reader["Phone"]?.ToString() ?? "", PassportOrId = reader["passportOrId"].ToString(), Rooms = new List <Room>(), OrderId = reader["OrderId"].ToString(), CheckinDate = DateTime.Parse(reader["CheckinDate"].ToString()), CheckoutDate = DateTime.Parse(reader["CheckoutDate"].ToString()) }; var roomId = reader["RoomId"].ToString(); var activeItem = list.FirstOrDefault(c => c.Id == item.Id); if (activeItem == null) { item.Rooms.Add(allRooms.Single(r => r.Id == roomId)); list.Add(item); } else { activeItem.Rooms.Add(allRooms.Single(r => r.Id == roomId)); } } return list; })); }
public static List <BookingOrder> GetOrdersInRange(string houseId, DateTime startDate, DateTime endDate) { return(SqlHelper.ExecuteReader(SP_ORDER_SELECT_IN_RANGE, new[] { new SqlParameter("@houseId", houseId), new SqlParameter("@startDate", startDate), new SqlParameter("@endDate", endDate), }, reader => { var result = new List <BookingOrder>(); while (reader.Read()) { var order = new BookingOrder { Id = reader["Id"].ToString(), CheckinDate = DateTime.Parse(reader["CheckinDate"].ToString()), CheckOutDate = DateTime.Parse(reader["CheckoutDate"].ToString()), Note = reader["Note"]?.ToString() ?? string.Empty, Status = reader["Status"].ToString(), TotalGuest = int.Parse(reader["TotalGuest"].ToString()), StayLength = reader["StayLength"].ToString(), HouseId = reader["HouseId"].ToString(), Rooms = new List <Room>() }; result.Add(order); } reader.NextResult(); var mapping = result.ToDictionary(o => o.Id, o => o); var rooms = RoomService.GetRooms(houseId); var roomMapping = rooms.ToDictionary(r => r.Id, r => r); while (reader.Read()) { var order = mapping[reader["OrderId"].ToString()]; order.Rooms.Add(roomMapping[reader["RoomId"].ToString()]); } return result; })); }