public WashTime FindWashTime() { WashTime washTime = null; bool found = false; var list = (from w in WashTimes select w).ToList().OrderBy(w => w.fromTime); foreach (WashTime wt in list) { if (!found) { if (DateTime.Today + wt.fromTime.GetValueOrDefault() >= DateTime.Now) { washTime = wt; found = true; } else if (DateTime.Today + wt.toTime.GetValueOrDefault() >= DateTime.Now) { washTime = wt; found = true; } } } if (!found) { throw new Exception("Sorry its too late/early to start a machine"); } return(washTime); }
public void Init() { laundryRoom = new LaundryRoom(); laundryRoom.Machines.Add(new Machine()); laundryRoom.Machines.Add(new Machine()); laundryRoom.Machines.Add(new Machine()); laundryUser = new LaundryUser(); laundryUser.name = "Namjoo"; reservation = new Reservation(); washTime = new WashTime(); washTime.fromTime = DateTime.Now.AddMinutes(10).TimeOfDay; reservation.WashTime1 = washTime; laundryUser.Reservations.Add(reservation); }