示例#1
0
        public Stay PlaceAnimal(Stay stay, Lodging lodge)
        {
            Lodging newLodge = _lodgingRepository.FindByID(lodge.ID);
            Stay    newStay  = new Stay();

            try
            {
                if (stay.ID == null || stay.ID == 0)
                {
                    newStay.LodgingLocationID = newLodge.ID;
                    newStay.AnimalID          = stay.AnimalID;
                    newStay.ArrivalDate       = stay.ArrivalDate;
                    newStay.CanBeAdopted      = stay.CanBeAdopted;
                    ValidateStay(newStay);
                }
                else
                {
                    newStay = _stayRepository.FindByID(stay.ID);
                }

                // If animal moved
                if (newStay.LodgingLocationID != newLodge.ID && newStay.LodgingLocationID != null)
                {
                    newStay.LodgingLocationID = newLodge.ID;
                    ValidateStay(newStay);

                    Lodging currentLodge = _lodgingRepository.FindByID(newStay.LodgingLocationID);

                    // Decrease capacity at old lodge
                    currentLodge.CurrentCapacity = currentLodge.CurrentCapacity - 1;
                    currentLodge.Stays.Remove(newStay);
                    _lodgingRepository.SaveLodging(currentLodge);
                }

                SaveStay(newStay);

                // Increase capacity at new lodge
                newLodge.CurrentCapacity = newLodge.CurrentCapacity + 1;

                newLodge.Stays.Add(newStay);
                _lodgingRepository.SaveLodging(newLodge);

                return(newStay);
            } catch (InvalidOperationException e)
            {
                throw e;
            }
        }
示例#2
0
 public Lodging FindByID(int ID)
 {
     // Add specific business logic here
     return(_lodgingRepository.FindByID(ID));
 }