Пример #1
0
        //Deletes one dog and all the related services for that dog from a reservation.
        //If there is only one dog in the reservation, the reservation is cancelled.
        public int DeleteDogFromReservation(int reservationNumber, int petNumber)
        {
            e errCode = e.success;

            if (Validation.invalidRes(reservationNumber))
            {
                errCode = e.invalidRes;
            }
            else if (Validation.invalidPet(petNumber))
            {
                errCode = e.invalidPet;
            }
            else if (Validation.petNotInRes(petNumber, reservationNumber))
            {
                errCode = e.petNotInRes;
            }
            else
            {
                PetReservation petRes = new PetReservation();
                Service        serv   = new Service();
                foreach (PetReservation pr in petRes.ListPetReservations().Where(pr => pr.reservationNum == reservationNumber))
                {
                    serv.Delete(pr.petResNum);
                }
                petRes.RemovePetFromRes(petNumber, reservationNumber);
            }
            return(Convert.ToInt16(errCode));
        }
Пример #2
0
        public e removePet(int petNumber)
        {
            e errCode = e.success;


            PetReservation        petRes     = new PetReservation();
            List <PetReservation> petResList = petRes.ListPetReservations().FindAll(p => p.petNum == petNumber);

            Reservation res = new Reservation();

            for (int i = 0; i < petResList.Count; i++)
            {
                if (res.ListActiveReservation().Find(r => r.number == petResList[i].reservationNum) != null)
                {
                    errCode = e.petInRes;
                }
            }

            if (errCode == e.success)
            {
                PetDB petDB = new PetDB();
                if (petDB.Delete(petNumber) == false)
                {
                    errCode = e.deleteFail;
                }
            }
            return(errCode);
        }
Пример #3
0
        //Cancels a reservation
        public int CancelReservation(int reservationNumber)
        {
            e errCode = e.success;

            if (Validation.invalidRes(reservationNumber))
            {
                errCode = e.invalidRes;
            }
            if (Validation.activeRes(reservationNumber))
            {
                errCode = e.activeRes;
            }
            else
            {
                ReservationDB  resDB = new ReservationDB();
                PetReservation pr    = new PetReservation();
                Discount       d     = new Discount();
                d.removeDiscount(reservationNumber);
                pr.RemoveEntireRes(reservationNumber);
                if (!resDB.Delete(reservationNumber))
                {
                    errCode = e.deleteFail;
                }
            }

            return(Convert.ToInt16(errCode));
        }
Пример #4
0
 public override bool Equals(Object pr)
 {
     if (pr.GetType() == typeof(PetReservation))
     {
         PetReservation pr2 = (PetReservation)pr;
         return(this.petResNum == pr2.petResNum);
     }
     else
     {
         return(false);
     }
 }
Пример #5
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));
        }
Пример #6
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);
        }
Пример #7
0
        public static List <PetReservation> ListPetReservationsDir()
        {
            PetReservation pr = new PetReservation();

            return(pr.ListPetReservations());
        }
Пример #8
0
 public static bool petInRes(int petNum, int resNum)
 {
     return(PetReservation.ListPetReservationsDir().Any(pr =>
                                                        pr.reservationNum == resNum && pr.petNum == petNum));
 }
Пример #9
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);
        }