public static List<IReservation> GetReservations() { List<IReservation> reservationsList = new List<IReservation>(); List<IEmployee> employeeList = GetEmployees(); List<IMachine> machineList = GetMachines(); List<ReservationEntity> reservationEntityList = Persistens.GetAllReservationEntities(); foreach (ReservationEntity reservationEntity in reservationEntityList) { IMachine machineFromList = null; IEmployee employeeFromList = null; foreach (IMachine machine in machineList) { if (machine.Id == reservationEntity.Machine) { machineFromList = machine; } } foreach (IEmployee employee in employeeList) { if (employee.Id == reservationEntity.User) { employeeFromList = employee; } } Machine mac = new Machine(machineFromList.Name, machineFromList.Type, machineFromList.Status, machineFromList.Id); Employee emp = new Employee(employeeFromList.Id, employeeFromList.Name, employeeFromList.Experience); IReservation res = new Reservation(emp, mac, reservationEntity.Day, reservationEntity.Start, reservationEntity.End, reservationEntity.JamType, reservationEntity.Description, reservationEntity.Id); reservationsList.Add(res); } return reservationsList; }
public static List<IReservation> GetReservations(IMachine machine, DateTime day) { List<ReservationEntity> reservationEntities = Persistens.GetAllReservationEntities(); List<IReservation> reservationsList = new List<IReservation>(); List<IMachine> machineList = GetMachines(); List<IEmployee> employeeList = GetEmployees(); foreach(ReservationEntity entity in reservationEntities) { if (machine.Id == entity.Machine) { // The current Reservation conserns the choosen Machine if (day.Date.Equals(entity.Day.Date)) { Machine thisMachine = null; Employee thisEmployee = null; foreach (IMachine currentMachine in machineList) { if (currentMachine.Id.Equals(entity.Machine)) { thisMachine = (Machine)currentMachine; } } foreach (IEmployee currentEmployee in employeeList) { if (currentEmployee.Id.Equals(entity.User)) { thisEmployee = (Employee)currentEmployee; } } if (thisMachine != null && thisEmployee != null) { // The current Reservation happened the choosen Day IReservation reservation = new Reservation(thisEmployee, thisMachine, entity.Day, entity.Start, entity.End, entity.JamType, entity.Description, entity.Id); reservationsList.Add(reservation); } else { // The current Reservation happened the choosen Day IReservation reservation = new Reservation(entity.User, entity.Machine, entity.Day, entity.Start, entity.End, entity.JamType, entity.Description, entity.Id); reservationsList.Add(reservation); } } } } return reservationsList; }