Пример #1
0
        public async Task <BookedDate> BookDate(DateTime startDate, DateTime endDate, string offerId)
        {
            var offer = await database.OfferRepository.Get(offerId);

            if (offer == null)
            {
                return(null);
            }

            var currentUser = await profileService.GetCurrentUser();

            if (currentUser.Id == offer.CreatorId)
            {
                Alertify.Push("You are owner of this offer", AlertType.Warning);
                return(null);
            }

            if (!bookingValidationService.IsBookingDateAvailable(startDate, endDate, offer))
            {
                Alertify.Push("This date is already booked", AlertType.Warning);
                return(null);
            }

            if (currentUser != null && bookingValidationService.HasUserAnotherBookedDate(currentUser, offer.Id))
            {
                Alertify.Push("You have already booked this offer", AlertType.Warning);
                return(null);
            }

            var bookedDate = BookedDate.Create(startDate, endDate);

            offer.BookedDates.Add(bookedDate);

            if (currentUser != null)
            {
                currentUser.BookedDates.Add(bookedDate);
            }

            return(await database.Complete() ? bookedDate : null);
        }