Same person can only have 1 reservation on the same day
Question

I'm building a restaurant reservation app and the same person can only have one reservation per day, how can I add a validator like a phone number for example? In my app, the user fills in a form and when clicking the submit button, the data goes directly to my database.

mvp_badge
MVP

Nothing goes "directly to the database". There is code (in a Screen Action) that is triggered when the user presses a button. Check the code, and add all the checks you need.

mvp_badge
MVP

So what's your question?

this is the flow of my button, when the customer clicks it redirects to a screen that confirms that the reservation was made and I already have access to it in the database. As I'm still not very familiar with the platform, I didn't quite understand where I should apply the solution you proposed.

mvp_badge
MVP

Do you have prior programming experience? Because where to place logic for checking before saving is not platform-specific, it's more of a general programming thing. Think about your logic flow: if you want to check whether something is valid before saving, where should you place that logic?

I actually have. Do I know that the condition must go in the form valid? for it to be false, I just don't know where on the platform I apply the condition. I started using the platform less than 12 hours ago so I think it's normal to be a little lost even though I know how to program.

mvp_badge
MVP

Hi Caroline,

Great, in that case, I can see your confusion. The Form.IsValid property just identifies whether any default validations pass or not (like does an Integer input actually contain a number, are all mandatory fields filled, etc.). For custome validations like "does this customer have another reservation for today", you need to write custom validation code. So if the form is valid (the downward flow after the If), you put some extra checking logic (before actually saving).

how do i compare with what i have in the database? if the phone number and date are the same as one that already exists in the database, the form is false. How do I compare with the database?

mvp_badge
MVP

If need to retrieve it from the database. So you need a query that searches the database for a record with that phone number and that input date. Make sure to set the Fetch property to "On Demand" and refresh the query in your action.

Entendo o que você quer dizer, cria uma condição que verifica esses dados antes de criar um novo, mas minha sintaxe não está correta, você pode me ajudar?


mvp_badge
MVP

Please communicate in English...

mvp_badge
MVP

"I understand what you mean, create a condition that checks this data before creating a new one, but my syntax is not correct, can you help me?"

You have a "GetClientById", but if it's really fetching by Id that's not ok, you want to fetch by phone number and date. Also, you then check the List.Empty - if it's True, there's no conflicting record, if it's False, then you need to bail out with a message.

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.