|
|
|
@@ -164,7 +164,7 @@ namespace Fitness_core_BE.Services
|
|
|
|
|
await _uow.BeginAsync();
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var (facility, startTime, endTime, partySize) = await ValidateAdhocRequestAsync(payload);
|
|
|
|
|
var (facility, startTime, endTime, partySize, _) = await ValidateAdhocRequestAsync(payload);
|
|
|
|
|
|
|
|
|
|
var cusId = await _userRoleHelper.GetCusId(DataExtractor.GetUserIdFromContext(httpContext));
|
|
|
|
|
|
|
|
|
@@ -202,7 +202,7 @@ namespace Fitness_core_BE.Services
|
|
|
|
|
await _uow.BeginAsync();
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var (facility, startTime, endTime, partySize) = await ValidateAdhocRequestAsync(payload);
|
|
|
|
|
var (facility, startTime, endTime, partySize, pricePerHour) = await ValidateAdhocRequestAsync(payload);
|
|
|
|
|
|
|
|
|
|
var data = DeserializePayload.Deserialize(payload);
|
|
|
|
|
var guestName = data["guestName"].GetString() ?? throw new ArgumentException("guestName is required");
|
|
|
|
@@ -223,7 +223,10 @@ namespace Fitness_core_BE.Services
|
|
|
|
|
GuestName = guestName,
|
|
|
|
|
GuestPhone = guestPhone,
|
|
|
|
|
OtpCode = GenerateOtp(),
|
|
|
|
|
AmountCharged = Math.Round(facility.PricePerHour * durationHours, 2),
|
|
|
|
|
// Staff can override the facility's default rate per booking (e.g. a discount)
|
|
|
|
|
// -- the pre-filled suggestion in the FE comes from facility.PricePerHour, but
|
|
|
|
|
// the charge actually uses whatever rate was submitted.
|
|
|
|
|
AmountCharged = Math.Round((pricePerHour ?? facility.PricePerHour) * durationHours, 2),
|
|
|
|
|
PaymentStatus = "Unpaid",
|
|
|
|
|
Status = "Confirmed"
|
|
|
|
|
};
|
|
|
|
@@ -244,7 +247,7 @@ namespace Fitness_core_BE.Services
|
|
|
|
|
/// requested window must have a free unit. Locks the facility row for the duration of the
|
|
|
|
|
/// caller's transaction so two concurrent claims on the same facility serialize instead of
|
|
|
|
|
/// both reading "room available" before either commits.</summary>
|
|
|
|
|
private async Task<(Facility facility, DateTime startTime, DateTime endTime, int? partySize)> ValidateAdhocRequestAsync(object payload)
|
|
|
|
|
private async Task<(Facility facility, DateTime startTime, DateTime endTime, int? partySize, decimal? pricePerHour)> ValidateAdhocRequestAsync(object payload)
|
|
|
|
|
{
|
|
|
|
|
var data = DeserializePayload.Deserialize(payload);
|
|
|
|
|
var facilityId = Guid.Parse(data["facilityId"].GetString()!);
|
|
|
|
@@ -257,6 +260,14 @@ namespace Fitness_core_BE.Services
|
|
|
|
|
? data["partySize"].GetInt32()
|
|
|
|
|
: null;
|
|
|
|
|
|
|
|
|
|
// Optional per-booking rate override -- the FE pre-fills this from the facility's
|
|
|
|
|
// own PricePerHour but lets staff adjust it (e.g. a discount) before charging.
|
|
|
|
|
decimal? pricePerHour = data.ContainsKey("pricePerHour") && data["pricePerHour"].ValueKind != JsonValueKind.Null
|
|
|
|
|
? data["pricePerHour"].GetDecimal()
|
|
|
|
|
: null;
|
|
|
|
|
if (pricePerHour.HasValue && pricePerHour.Value < 0)
|
|
|
|
|
throw new ArgumentException("pricePerHour cannot be negative");
|
|
|
|
|
|
|
|
|
|
var facility = await _facilityRepository.GetFacilityById(facilityId)
|
|
|
|
|
?? throw new KeyNotFoundException("Facility not found");
|
|
|
|
|
if (facility.BookingMode != "AdHoc")
|
|
|
|
@@ -269,7 +280,7 @@ namespace Fitness_core_BE.Services
|
|
|
|
|
if (overlapping >= facility.NumberOfUnits)
|
|
|
|
|
throw new ArgumentException("No units are free for the requested time");
|
|
|
|
|
|
|
|
|
|
return (facility, startTime, endTime, partySize);
|
|
|
|
|
return (facility, startTime, endTime, partySize, pricePerHour);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ---------- Payment / check-in / lifecycle ----------
|
|
|
|
|