public async Task <GetCalendarAvailabilityViewModel> Handle(GetCalendarAvailabilityQuery query, CancellationToken cancellationToken)
        {
            var calendar = await _calendarRepository.GetByPropertyAsync(query.PropertyId);

            if (calendar == null)
            {
                throw new FantasticStayDomainException($"Cannot find calendar for property with id '{query.PropertyId}'.");
            }

            var availability = calendar.GetAvailability(query.From, query.To);

            return(new GetCalendarAvailabilityViewModel(query.PropertyId, query.From, query.To, availability));
        }
Пример #2
0
        public async Task <bool> Handle(BlockCalendarDatesCommand command, CancellationToken cancellationToken)
        {
            var calendar = await _calendarRepository.GetByPropertyAsync(command.PropertyId);

            if (calendar == null)
            {
                throw new FantasticStayDomainException($"Cannot find calendar for property with id '{command.PropertyId}'.");
            }

            calendar.BlockDates(command.From, command.To);

            _calendarRepository.Update(calendar);

            return(await _calendarRepository.UnitOfWork.SaveEntitiesAsync(cancellationToken));
        }
Пример #3
0
        public async Task <bool> Handle(AddCalendarAvailabilityCommand command, CancellationToken cancellationToken)
        {
            var calendar = await _calendarRepository.GetByPropertyAsync(command.PropertyId);

            if (calendar == null)
            {
                throw new FantasticStayDomainException($"Cannot find calendar for property with id '{command.PropertyId}'.");
            }

            var price = new Price(command.Amount, command.CurrencyId);

            calendar.AddAvailability(command.From, command.To, price);

            _calendarRepository.Update(calendar);

            return(await _calendarRepository.UnitOfWork.SaveEntitiesAsync(cancellationToken));
        }
Пример #4
0
        public async Task <bool> Handle(CreateCalendarCommand command, CancellationToken cancellationToken)
        {
            var property = await _propertyRepository.GetAsync(command.PropertyId);

            if (property == null)
            {
                throw new FantasticStayDomainException($"Cannot find property with id '{command.PropertyId}'.");
            }

            var calendar = await _calendarRepository.GetByPropertyAsync(property.Id);

            if (calendar != null)
            {
                return(true);
            }

            calendar = new Calendar(property.Id);

            _logger.LogInformation("Creating Calendar - {@Calendar}", calendar);

            _calendarRepository.Add(calendar);

            return(await _calendarRepository.UnitOfWork.SaveEntitiesAsync(cancellationToken));
        }