public async Task <IActionResult> OnPostAsync() { if (ModelState.IsValid) { int checkInTimeInt; int checkOutTimeInt; try { checkInTimeInt = int.Parse(CheckInTime.Split(":")[0]); checkOutTimeInt = int.Parse(CheckOutTime.Split(":")[0]); } catch { return(BadRequest()); } if (checkInTimeInt <= checkOutTimeInt) { ModelState.AddModelError("CheckInTime", "Check-in time must be later than check-out time!"); Accommodation = await accommodationLogic.GetAccommodationByIdAsync(AccommodationId); Currencies = await currencyLogic.GetCurrenciesAsync(); return(Page()); } var accommodationImagesFolderPath = Path.Combine(webHostEnviroment.WebRootPath, "accommodationPhotos"); Accommodation = await accommodationLogic.GetAccommodationByIdAsync(AccommodationId); if (Accommodation.ApplicationUser.UserName != User.Identity.Name) { return(Unauthorized()); } var result = await accommodationLogic.UpdateAccommodationAsync(AccommodationId, Name, NumberOfBeds, PricePerNight, CurrencyId, RequireApproval, UserCanCancelBooking, CheckInTime, CheckOutTime, Accommodation.Name, accommodationImagesFolderPath); if (!result) { return(BadRequest()); } return(RedirectToPage("/Accommodations")); } return(BadRequest()); }
public async Task <IActionResult> OnPostAsync() { if (ModelState.IsValid) { int checkInTimeInt; int checkOutTimeInt; try { checkInTimeInt = int.Parse(CheckInTime.Split(":")[0]); checkOutTimeInt = int.Parse(CheckOutTime.Split(":")[0]); } catch { return(BadRequest()); } if (checkInTimeInt <= checkOutTimeInt) { ModelState.AddModelError("CheckInTime", "Check-in time must be later than check-out time!"); //this is required as the page requires accommodationTypes list populated in order to display the //accommodation type select list and currency select list AccommodationTypes = await AccommodationTypeLogic.GetAccommodationTypesAsync(); Currencies = await CurrencyLogic.GetCurrenciesAsync(); return(Page()); } var accommodationPhotosRootFolder = Path.Combine(webHostEnvironment.WebRootPath, "accommodationPhotos"); var result = await AccommodationLogic.CreateNewAccomodationAsync(Name, City, Address, NumberOfBeds, PricePerNight, CurrencyId, RequireApproval, AccommodationTypeId, CheckInTime, CheckOutTime, User.Identity.Name, UserCanCancelBooking, accommodationPhotosRootFolder, AccommodationHeaderPhoto, AccommodationPhotos); if (!result) { return(BadRequest()); } return(RedirectToPage("/Accommodations")); } else { return(BadRequest()); } }