public async Task <IActionResult> GetCottageById(int id,
                                                         bool includeCalendar = false,
                                                         bool includeOwners   = false,
                                                         bool includeMinPrice = false,
                                                         DateTime?arrivalDate = null,
                                                         int noOfNights       = 0)
        {
            if (User.IsInRole("Customer") && includeOwners)
            {
                return(Unauthorized());
            }

            var cottage = await _repo.GetCottageById(id, includeCalendar, includeOwners);

            if (cottage == null)
            {
                return(NotFound());
            }

            var cottageToReturn = _mapper.Map <CottageDto>(cottage);

            cottageToReturn.MinPrice7Nights = (includeMinPrice) ? Prices.MinPrice7Nights(cottage.Calendar) : 0;

            cottageToReturn.RequestedPrice = (arrivalDate.HasValue) ? Prices.PriceForDates(cottage.Calendar, arrivalDate.Value, noOfNights) : 0;

            return(Ok(cottageToReturn));
        }
Ejemplo n.º 2
0
        private async Task <Cottage> UpdateCottageCalendar(PendingBooking pendingBooking)
        {
            var cottageAndCalendar = await _repo.GetCottageById(pendingBooking.CottageId, true, false);

            var holidayDays = cottageAndCalendar.Calendar.Where(d => d.BookingDate >= pendingBooking.ArrivalDate &&
                                                                d.BookingDate < pendingBooking.LeavingDate).ToList();

            holidayDays.ForEach(d => {
                d.BookingStatus = Enums.BookingStatus.Booked;
                d.ModifiedDate  = DateTime.Now;
                d.ModifiedBy    = pendingBooking.CreatedBy;
            });

            return(cottageAndCalendar);
        }