public bool IsSatisfiedBy(Entities.CulturalExchange entity)
        {
            if (!entity.OurAccomodation || !entity.AccomodationId.HasValue)
            {
                return(true);
            }

            if (entity.StartAccomodation == null || entity.FinishAccomodation == null)
            {
                return(true);
            }

            Accomodation accomodation = _accomodationRepository.GetById(entity.AccomodationId.Value);

            entity.DaysOfAccomodation = ((TimeSpan)(entity.StartAccomodation - entity.FinishAccomodation)).Days * 100;

            var culturalExchangeInAccomodation = _accomodationRepository.GetAccomodationAndCulturalExchangeList(entity.AccomodationId.Value);

            var reservations = culturalExchangeInAccomodation.CulturalExchanges.Where(x => x.StartAccomodation <= entity.StartAccomodation &&
                                                                                      x.FinishAccomodation >= entity.FinishAccomodation &&
                                                                                      x.OurAccomodation).ToList();

            if (reservations.Count >= accomodation.NumberOfPlaces)
            {
                entity.ValidationResult.Add(new ValidationResult("Date Start Accomodation invalid"));
            }

            return(true);
        }
Пример #2
0
        public Accomodation GetAccomodationAndCulturalExchangeList(Guid id)
        {
            var accomodation = _accomodationRepository.GetAccomodationAndCulturalExchangeList(id);

            accomodation.CulturalExchanges.ForEach(ce =>
            {
                ce.Student     = _studentRepository.GetById(ce.StudentId);
                ce.CollegeTime = _collegeTimeRepository.GetById(ce.CollegeTimeId);
                ce.College     = _collegeRepository.GetById(ce.CollegeId);
            });

            return(accomodation);
        }