save method

Future<bool> save()

Creates or updates the reservation. Returns true when the dialog can close.

Implementation

Future<bool> save() async {
  if (editing != null) {
    return await send(
          UServices.hotel.updateHotelReservation(
            p: UHotelReservationUpdateParams(
              id: editing!.id,
              checkInDate: checkIn,
              checkOutDate: checkOut,
              guestCount: intOf(guestCountController),
              totalPrice: numOf(totalPriceController),
              guestName: guestNameController.text.nullIfEmpty(),
              guestPhone: guestPhoneController.text.nullIfEmpty(),
              notes: notesController.text.nullIfEmpty(),
            ),
          ),
          read,
        ) !=
        null;
  }
  if (formRoom == null) {
    UToast.error(message: U.s.pleaseSelectAItem(U.s.room));
    return false;
  }
  if (formUser == null) {
    UToast.error(message: U.s.pleaseSelectAItem(U.s.user));
    return false;
  }
  return await send(
        UServices.hotel.createHotelReservation(
          p: UHotelReservationCreateParams(
            tags: <int>[TagHotelReservation.pending.number],
            checkInDate: checkIn!,
            checkOutDate: checkOut!,
            guestCount: intOf(guestCountController) ?? 1,
            userId: formUser!.id,
            roomId: formRoom!.id,
            totalPrice: numOf(totalPriceController),
            guestName: guestNameController.text.nullIfEmpty(),
            guestPhone: guestPhoneController.text.nullIfEmpty(),
            notes: notesController.text.nullIfEmpty(),
            penaltyPrecentEveryDate: intOf(penaltyController),
          ),
        ),
        read,
      ) !=
      null;
}