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);
        }
        public List <CulturalExchange> GetAll(Guid idEnvironment, bool active)
        {
            var culturalExchangeEntity = _culturalExchangeRepository
                                         .FindByFilter(x => x.Environment.Id == idEnvironment && x.Available == active);

            culturalExchangeEntity.ForEach(x =>
            {
                x.College = _collegeRepository.GetById(x.CollegeId);

                if (x.AccomodationId.HasValue)
                {
                    x.Accomodation = _accomodationRepository.GetById(x.AccomodationId.Value);
                }

                x.Student     = _studentRepository.GetById(x.StudentId);
                x.CollegeTime = _collegeTimeRepository.GetById(x.CollegeTimeId);
            });

            return(culturalExchangeEntity);
        }
Exemple #3
0
 public Accomodation GetById(Guid id)
 {
     return(_accomodationRepository.GetById(id));
 }