public async Task <IActionResult> OnGetAsync(int accommodationId) { if (accommodationId == 0) { return(BadRequest()); } Accommodation = await accommodationLogic.GetAccommodationByIdAsync(accommodationId); if (Accommodation.ApplicationUser.UserName != User.Identity.Name) { return(Unauthorized()); } var accommodationPhotosFolder = accommodationLogic.GetPhotosFolderPathForAccommodation(Accommodation); //removing the wwwroot prefix HeaderPhotoPath = accommodationPhotosFolder + "Header/" + Accommodation.HeaderPhotoFileName; HeaderPhotoPath = HeaderPhotoPath.Substring(7); try { AccommodationPhotos = Directory.GetFiles(accommodationPhotosFolder, "*", SearchOption.TopDirectoryOnly).ToList(); } catch { AccommodationPhotos = new List <string>(); } return(Page()); }
public async Task <IActionResult> OnGetAsync(int accommodationId, string checkInDate, string checkOutDate) { if (accommodationId == 0) { return(BadRequest()); } if (User.Identity.IsAuthenticated) { CurrentUser = await userManager.FindByEmailAsync(User.Identity.Name); } AccommodationId = accommodationId; Accommodation = await AccommodationLogic.GetAccommodationByIdAsync(accommodationId); if (Accommodation == null) { return(NotFound()); } CheckInDateString = checkInDate; CheckOutDateString = checkOutDate; var dateformat = "dd.MM.yyyy."; var listOfDatesOccupied = await AccommodationLogic.GetDatesOccupiedForAccommodationAsync(accommodationId); try { CheckInDate = DateTime.ParseExact(checkInDate, dateformat, CultureInfo.InvariantCulture); CheckOutDate = DateTime.ParseExact(checkOutDate, dateformat, CultureInfo.InvariantCulture); if (CheckInDate < DateTime.Now.Date || CheckOutDate < DateTime.Now.AddDays(1).Date || CheckInDate >= CheckOutDate) { throw new Exception("Invalid dates!"); } if (!await AccommodationLogic.CheckIfBookingDatesAreValid(CheckInDate, CheckOutDate, accommodationId)) { throw new Exception("Dates are occupied!"); } } catch { CheckInDate = DateTime.Now.Date; CheckOutDate = DateTime.Now.Date; CheckInDateString = CheckInDate.ToString(dateformat); CheckOutDateString = CheckOutDate.ToString(dateformat); } DatesOccupiedArray = listOfDatesOccupied.ToArray(); var accommodationPhotosFolder = AccommodationLogic.GetPhotosFolderPathForAccommodation(Accommodation); HeaderPhotoPath = accommodationPhotosFolder + "Header/" + Accommodation.HeaderPhotoFileName; //removing wwwroot prefix HeaderPhotoPath = HeaderPhotoPath.Substring(7); try { AccommodationPhotos = Directory.GetFiles(accommodationPhotosFolder, "*", SearchOption.TopDirectoryOnly).ToList(); } catch (Exception) { AccommodationPhotos = new List <string>(); } return(Page()); }