Now here, we need to work on what should happen when we're updating a product, and the post action
method is called.
First, we will check if the model state is valid or not.
That is correct after that.
If the file is not, now we upload the file, but we need to make sure of one thing when we are updating,
when we are updating an already existing image.
We first need to delete an image that exist inside images products.
So before we copy the new image right here, we can check if inside the object product, that image
you are.
If that is not, no, this means there is an existing image inside the database.
So in that case, let's get the old image that we have to do that start to combine.
We have to look back.
And with that, what we need to combine is the image You are real.
Now, if you notice here with image, you are in fact database.
We are adding a backwards flash when we use metadata combined.
We do not write that.
So we will have to trim that forward slash from object product.
That image you are l with will see trim start.
We want to trim the forward slash if you write just one forward words that it takes the Netscape character.
So you would have to write that two times.
Once we have the complete back, we can see a system that are you that file that exist.
We will first check if any file exists in this old pad.
If it does, then we want to delete that.
So systems that are you that fail to delete?
So that means the old image will be removed here and then the world will be updated after that when
we are calling the add here with their check OPG product that.
If that is equal to zero, that means it's an ad in the ads part.
We want to call the update, so give it a copy and paste this within called the update method and set
the update if the image you are rolling.
Now we are not updating anything at all.
So that is perfect.
So our update logic looks good.
Let's run the application and try to update our product.
Let's go to product here.
Let's try to update this.
And let me go back to the images, we have the fortune of time.
Let's create the same title.
We have updated the details here that produced the image, which is fortune off time.
Let's go back.
The image that we have already is that leaf image.
So that's perfect.
We'll see if that gets updated with select action and soft cover as soon as you hit the update button.
You will see something weird.
Let me show with that.
Let's check the update button.
What effect you can see, what actually happened is it did not update the existing entry, but actually
it created a new entry.
So I want you guys to add a debunking point and try to find out on why it is creating a new record rather
than updating the existing record.