All right, guys.
So this has been quite the journey and we're at the end of this section.
At this point, you should have a fully data driven app that can perform CRUD and you can put yourself
on the back.
You've come a far away with Maui development.
Now I just want to walk you through some of the well, the solution to some of the problems that I would
have given you earlier.
And we can, you know, compare notes.
I would love to see how you did it to what your implementations are.
I will show you mine.
So I would have left you with a challenge to implement that update functionality.
So my challenge would be that when you click update, you will populate the form with the detail.
You change the text of the button and after modifying you would click update it successful and reload.
And then if I tap that, you'll see that, yes, that update was successful.
I just added all of those ways.
Right.
So that is what I would suggest that I also cleared the form after the successful operation and I implemented
that clear form.
But so let me just walk you through what I did.
So for the update button, I would have created this method called set update.
So edit mode command, right?
So that's a brand new command set edit mode for the create button.
I would have added a text binding that says add edit button text and I would have created a new command
called Save Car for the clear button.
I would have created a new command as is clear form.
So I got rid of the fetch list button and I'm just seeing clear form command.
All right.
So in the view model.
I mean, just collapse everything so we can see.
So let's focus on our safe car first.
All right, let me let me look at the edit mode first.
So let me bring in into ardour.
So when you click update, it would set the add edit button text to be edit put in text.
So that's actually a concern spring string that I put on top of edit button takes that says update car
and the nav create button takes us as at car.
So based on the situation, I'm setting the button text.
So in its edit mode we are going to see add edit button text is equal to edit button text.
I'm also going to set brand new property that I call car ID and that is an observable property.
I am setting that to be I.D. So whatever IDs passed in because remember that would have in passing in
that I.D. on that button anyway.
Right.
Branding is ID.
So I'm getting that idea and I'm setting it within the context of or within the binding context of the
farm.
I'm also fetching the record from the database and then I'm setting all of the observable properties
to have the appropriate values coming from the database.
That way, when we update this in the code that bubbles up to the UI and we know how that works by now.
So that is what makes it up here in the form.
Once I click that button that cause this command, no after it has appeared and you make it changes
on whatever.
I think I started working on this one and then I abandon this method so I could actually remove that.
But let's not pay attention to what we don't need to pay attention to.
I refactor the save car so I had add car command and it saved car command.
And now I'm doing save car because I don't know if it's going to be an edit or it's going to be an add.
It doesn't make sense to have two buttons either.
Right?
So I'm using the same button to just save the car.
I still have my validation.
And I'm still going to create that total object, right?
So I'm still doing these two things.
However, I'm using the car idea as an indicator as to whether I'm supposed to be editing or adding.
Because when I set edit mode, I set it to a value.
Originally it wouldn't have a value, right?
It would actually have zero as a value.
So once I say once it is not equal to zero, then go ahead and set the ID value on the car card.
If you know how updates work, you have to have that ID present so that it knows that this is not a
new record.
So once I set that card out I.D., I'm going to call update car, which is pretty simple and pretty
similar to what we've done so far.
We need to check if it's now and then this I would just say conduct update pass in the car and then
we have the same kind of lambda sorry, the same kind of ternary operator checking the value of results.
Right.
So that's that's pretty straightforward compared to what we've done for adding that it's almost the
same syntax.
So.
After we call the update, then I display the alert ls meaning car I.D is actually equivalent to zero
and we are seeing as a new car we just go ahead.
And so we don't need the I.D., right?
We just need those like we had before and then we display our alert.
Then I refresh the list and then look at this.
I clear the form.
Now what does clear form do for me?
Clear form just means I'm going to reset all the values in the binding context.
So one, I'm going to reset the button takes to be credit, create button text, because when the form
loads, it's an empty form.
So obviously the button should say add car, allow the user to fill out the car.
So we reset that to add car.
I set this back to zero and then I set all of the string values back to empty.
So blank text boxes are blank entries on the screen altogether also.
In the.
Constructor set the button takes to be created.
So once again when the page loads, what we want to see, want to see, create.
All right.
And that's pretty much it.
So I have actually uploaded this to GitHub.
I will be sharing this repository with you so you can look through.
And once again, I would love if you're back, so feel free to go on GitHub and leave feedback or ask
questions.
Raise an issue if you see anything wrong.
Once again, this is a simple enough app for us to get our appetites wet with Maui so that we can understand
and appreciate some of the intricacies that it's bringing and how we can just go about doing certain
things.