Esempio n. 1
0
        //20-29
        public static bool differentOwner(int petNum, int resNum)
        {
            List <Pet>            pets   = Pet.listPetsDir();
            List <PetReservation> petRes = PetReservation.ListPetReservationsDir();

            petRes.RemoveAll(pr => pr.reservationNum != resNum);

            return(petRes.Count == 0 ? false : pets.FindAll(p => petRes.Any(pr =>
                                                                            pr.reservationNum == resNum)).All(p =>
                                                                                                              p.ownerNumber == pets.Find(pp =>
                                                                                                                                         pp.number == petNum).ownerNumber));
        }
Esempio n. 2
0
        public int getOwner()
        {
            List <Pet>            findPet    = Pet.listPetsDir();
            List <PetReservation> findPetRes = PetReservation.ListPetReservationsDir();
            int owner;

            if (ownerNumber == null)
            {
                owner = Pet.listPetsDir().Find(p =>
                                               p.number == findPetRes.Find(pr =>
                                                                           pr.reservationNum == this.number).petNum).ownerNumber;
            }
            else
            {
                owner = -1;
            }

            return(owner);
        }
Esempio n. 3
0
 public static bool petInRes(int petNum, int resNum)
 {
     return(PetReservation.ListPetReservationsDir().Any(pr =>
                                                        pr.reservationNum == resNum && pr.petNum == petNum));
 }
Esempio n. 4
0
        public List <Run> ListAvailableRuns(DateTime startDate, DateTime endDate, char runSize)
        {
            Run        run           = new Run();
            List <Run> allRuns       = run.ListRuns().Where(r => runSize == 'L' ? r.size == 'L' : true).ToList();
            List <Run> runsAvailable = allRuns;

            Reservation allRes = new Reservation();
            //All reservations overlapping on a timeline

            /*
             *           Start --------------------------------------- End
             *      s-------------e        s---------------e    s----------------e
             *      s < start e > start    s > start e < end    s < end e > end
             *      s------------------------------------------------------------e
             *                             s < start e > end
             */
            List <Reservation> resInRange = allRes.ListReservations().Where(r =>
                                                                            (r.sDate <= startDate && r.eDate >= startDate) ||
                                                                            (r.sDate >= startDate && r.eDate <= endDate) ||
                                                                            (r.sDate <= endDate && r.eDate >= endDate) ||
                                                                            (r.sDate <= startDate && r.eDate >= endDate)).ToList();
            List <PetReservation> allPetRes = PetReservation.ListPetReservationsDir().Where(pr =>
                                                                                            resInRange.Any(r => r.number == pr.reservationNum)).ToList();
            List <Pet> allPets = Pet.listPetsDir();

            Func <List <Run>, List <PetReservation>, List <Run> > FindAssignedRuns = (runs, petRes) => {
                List <Run> retVal = runs.FindAll(r =>
                                                 (petRes.Any(pr => (pr.runNum != -1) ? pr.runNum == r.number : false) &&
                                                  ((runSize == 'L') ? r.size == 'L' : r.size != '~')));
                return(retVal);
            };

            Func <List <Run>, List <PetReservation>, List <Pet>, List <Run> > FindUnavailableUnbookedRuns = (runs, petRes, pets) => {
                List <Run> pseudoAssign = new List <Run>();
                List <Run> unassigned   = runs;
                foreach (PetReservation pr in petRes)
                {
                    if (unassigned.Count > 0)
                    {
                        Pet pp = pets.Find(p => p.number == pr.petNum);
                        Run rr = unassigned[0];
                        if (pp.size == 'L')
                        {
                            rr = unassigned.Find(r => r.size == 'L');
                            if (rr == null)
                            {
                                pseudoAssign.AddRange(unassigned);
                                break;
                            }
                        }
                        else
                        {
                            rr = unassigned.Find(r => r.size == 'R');
                            if (rr == null)
                            {
                                rr = unassigned[0];
                            }
                        }

                        if (rr != null)
                        {
                            pseudoAssign.Add(rr);
                            unassigned.Remove(rr);
                        }
                        else
                        {
                        }
                    }
                    else
                    {
                        break;
                    }
                }
                return(pseudoAssign);
            };

            List <Run> runToRemove1 = FindAssignedRuns(allRuns, allPetRes.FindAll(pr => pr.runNum != -1));

            runsAvailable.RemoveAll(r => runToRemove1.Any(rr => rr.number == r.number));

            List <PetReservation> unassigned2  = allPetRes.FindAll(rr => rr.runNum == -1);
            List <Run>            runToRemove2 = FindUnavailableUnbookedRuns(runsAvailable, unassigned2, allPets);

            runsAvailable.RemoveAll(r => runToRemove2.Any(rr => rr.number == r.number));

            return(runsAvailable);
        }