Now to get functionality is working as expected.
Let's work on the post functionality so that we can create a product.
So if we go back to the application, let's open up the product controller.
Before we do anything inside the absurd post, we have to make sure that modern state is valid.
Now, if the modern state is valid, let's first handle this file or image that was uploaded.
What we want to do is we want to act that image inside the W W Road folder that will stop the application.
And create a new folder inside, they're having to create a folder of images, and inside they're able
to create a folder for products.
So immature be uploaded inside this products folder to access this w w w route.
We need that web hosting environment, so we would have to get that using dependency injection.
It is added to the application.
We just need to extract that and use that when we want to use the hosting environment.
So let me get that using dependency injection here.
And perfect weather, scroll down to our absurd post-election method.
So first thing that we have to do is get this w w w route that we can get that inside w w w that will
would bat variable that will be inside and discord host environment that the Webroot bat.
Then we want to make sure that the file is not now and this iPhone file.
Let me make that look right here.
So if the file is not now, that means the file was uploaded.
So here was a string file name is equal to let's generate a new file name, which will be a good start,
you know, good start to stream.
We do not want to use the existing name because typically in a production application, if someone uploads
two files with the same name, then it will be a mess.
So they are typically renamed and they are uploaded.
Then we need to find out the find a location where the file needs to be uploaded that is inside w WWE
Root.
We have images and products, so there is a variable upload is equal to.
We would have to combine the bad.
So it's a bad start.
We want that w w w root bad and we want to combine that with images forward slash products.
Make sure you did not make any spelling mistake here.
It should match exactly with the folders that he created.
Then we will rename the file, but we want to keep the same extension.
So here I will say extension is equal to bad that I have the matter to get extension that will get the
extension from the file name, which is insert file dot file name.
Make sure you are using file name and not to name their.
And finally, we need to copy the file that was uploaded inside the product folder, so at a using statement
and we'll say using VAR firestorms is equal to.
We will have to create a new extreme object to copy the file.
We will set fire to dark combine here and we want to combine part of the bad.
Let me hide this with the new file name, which is inside a fake name and the extension.
So that will give us the final bad.
We had to find needs to be uploaded, we're going to add a comma here.
The file more will be created.
So inside this using statement, we will be copying the file.
So I will say file doc copy, do we want to copy that file to the location that we have inside the fire
screen?
There's a simple code on how you can copy the fires in C Sharp.
We will modify our OPG, which is product fuel model.
In there, we have to try to start energy water.
This we will have to write that as images inside.
We have the products folder and then we will add the file name which will be acquired, plus the extension.
So that is what we're going to see in the database.
So at this point, the new image will be uploaded inside the folder and our product image, you know,
will be populated.
What we have to do here is on a unit of work, we have product.
We just have to add that product to our database.
And then here we will see a product added successfully are created successfully.
We don't add the mortgage here.
Inside there, we have the product model.
That is what we have to add.
So with that, let me save everything and run the application.
Let's try to create our first product.
I have the details populated.
Let me select an image here and hit that reset button.
We stayed on the same page and nothing happened.
Let me refresh the page here and try to create this one more time.
This time we're going to add a debugging point.
So let's go back here at a -- point.
I believe something in modern state is not valid.
And that's right.
Let's go to modern state and we have five errors.
Let's see what those errors are.
So here you see, it is trying to validate a category related cover type list.
It should not validate those.
Next, it is going inside the category object and tries to validate that with the image you are out
and cover type.
Now all of these properties should not validate right here.
But since it is tightly bind it to the model, it will automatically validate them.
So what is the workaround with that when we go to the product model right here?
We can set that we do not want to validate that every time this category is populated, that is not
the reason for adding a navigation property.
So here we have an attribute which is validated, never that we make sure that when we are checking
for model state, it will not validate the cover type category.
We also do not want the image to be validated.
If they scroll up, that looks good.
Let's go to our view model.
We do not want to validate our category list.
Let's look at that.
And perfect.
Let's run that application one more time.
Now, before Darknet six, when you were using darknet fi, the modern start date was not that strict.
They have made that change because of that it was failing.
Let's try to add a book again and see what happens.
We will select an image here and hit the reset button.
Armados said it's now true.
Let me debug here we have the Webroot pad, which will be the Pad two W W W Short folder.
Now, for some reason here, the file is now let me go back to the absurd view here and then let me
scroll up to where we have our file.
What if I got to give it a name of file as well that is needed once we give that name and the product
controller should be populated at unit of WorkSafe has not been executed.
So let me stop here and run the application one more time.
Let's go to product here and try to create a new product.
We will select an image.
And let's head to create pattern model state as well.
And file is also populated.
Let's press F10.
We have the new file name.
The extension is JPEG.
That's fine.
We are copying that file.
Let's make sure.
Yep, you can see it got created here.
We are populating our image.
You are real with the file name and extension, and we add that to our database.
Let's hit our five.
Product created successfully.
Let's go back to our database.
And let me select up Tauzin here, we should have our first product.
Now that our product has been created, let's work on displaying our product inside the product list.