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 bookingId, int accommodationId) { if (bookingId == 0 || accommodationId == 0) { return(BadRequest()); } Booking = await bookingLogic.GetBookingByIdAsync(bookingId); Accommodation = await accommodationLogic.GetAccommodationByIdAsync(accommodationId); if (Booking == null || Accommodation == null) { return(NotFound()); } //check if a user is trying to access some other user's booking - in that case deny the request //but if a host is trying to see a booking for one of his accommodations, allow it if (User.IsInRole("User") && Booking.ApplicationUser.UserName != User.Identity.Name) { return(Unauthorized()); } if (User.IsInRole("Host") && Accommodation.ApplicationUser.UserName != User.Identity.Name) { return(Unauthorized()); } return(Page()); }
public async Task <IActionResult> OnGetAsync(int accommodationId) { AccommodationId = accommodationId; if (accommodationId == 0) { return(BadRequest()); } var accommodation = await accommodationLogic.GetAccommodationByIdAsync(accommodationId); if (accommodation == null) { return(NotFound()); } if (accommodation.ApplicationUser.UserName != User.Identity.Name && !User.IsInRole("Admin")) { return(Unauthorized()); } var allBookingsForAccommodation = await bookingLogic.GetAllUpcomingBookingsForAccommodationAsync(accommodationId); NumberOfBookingsForAccommodation = allBookingsForAccommodation.Count(); return(Page()); }
public async Task <IActionResult> OnGetAsync(int accommodationId) { if (accommodationId == 0) { return(BadRequest()); } Accommodation = await accommodationLogic.GetAccommodationByIdAsync(accommodationId); if (Accommodation == null) { return(NotFound()); } if (Accommodation.ApplicationUser.UserName != User.Identity.Name) { return(Unauthorized()); } Currencies = await currencyLogic.GetCurrenciesAsync(); return(Page()); }
public async Task <IActionResult> OnGetForAccommodationAsync(int accommodationId) { if (accommodationId == 0) { return(BadRequest()); } var accommodationLogic = new AccommodationLogic(); var accommodation = await accommodationLogic.GetAccommodationByIdAsync(accommodationId); CurrentUser = await UserManager.GetUserAsync(User); if (CurrentUser == null) { return(BadRequest()); } if (accommodation.ApplicationUser.Id != CurrentUser.Id && !User.IsInRole("Admin")) { return(Unauthorized()); } PendingReservations = await BookingLogic.GetAllPendingReservationsForAccommodationAsync(accommodationId); ApprovedReservations = await BookingLogic.GetAllApprovedReservationsForAccommodationAsync(accommodationId); PreviousReservations = await BookingLogic.GetAllPreviousReservationsForAccommodationAsync(accommodationId); DeclinedReservations = await BookingLogic.GetAllDeclinedReservationsForAccommodationAsync(accommodationId); CancelledReservations = await BookingLogic.GetAllCancelledReservationsForAccommodationAsync(accommodationId); if (accommodation.UserCanCancelBooking) { CancelledByUserReservations = await BookingLogic.GetAllCancelledByUserReservationsForAccommodationAsync(accommodationId); } 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()); }