MVC how to show invoice and save order data in database in parent child relation

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello and welcome to horror map studio in this video i will show you how we can display an invoice of the user confirmed or after the payment to the user and get some data for the deliver for example for the delivery name of the user email phone etc for delivery and finally we will save all the data with the products the user have added into the card into our database table so as you know that i have already opened the project when i click in this project i have a basic flow i'm adding the product into the card changing the quantity if needed and finally click to this button proceed to the checkout and i will go to the payment uh gateway for the payment but i'm in the development mode and don't need to go every time to paypal so i can bypass the payment method directly without having pay anything i can go to the payment confirmation page and because i am in development mode it is not necessary every time to pay the amount off and as it is a time consuming process so i will bypass this payment gateway okay whenever i click on this button which is uh which is in shopping cart which is in shopping cart i will open shopping cart and when i click on this button it will go to the this url so i don't need to go to this url so i'll copy this url and paste it here one time okay now i'll simply go to my check uh con payment confirmation page directly without having paying this okay i will comment this code by using ctrl k control c and i'm here i will use the url url dot action method to go to my desired action method okay action will be the checkout action which is payment confirmation and it is in the shop controller and proceed whenever now uh when i click on this button it will go to directly payment confirmation page without uh going to without going to paypal method i'm going to refresh this page because i have changed a little behind this button the link have changed so i have to refresh this page one time okay now when i click this button it will go to this payment confirmation either without having to pay anything now we just need to show the user the product detail and the invoice which is we should be look like this okay this will be the user uh invoice uh which will included the product one product to prices and total etc and here we need some information about the order because we have to deliver this order later on it just is an online system and we need the user first name last name company name country etc uh not all the information necessary but some of the information is necessary the most important information is we need username what is the name which name we will transfer this order with the user phone in some cases the delivery wire cannot find the user uh then the table y will be able to call the user for receiving the and we need the address where we want to deliver this product so four things are most important and also we need an email so we can generate an email for the confirmation of the order okay we're going to add this uh this we're going to add this order and the billing information into this payment confirmation page in this page instead of this payment confirmed it is automatically show the invoice when the payment is confirmed okay uh this is our checkout page here we have just one thing the payment confirmed i'm going to remove all the code and here i will put the template code which is available in here in my template this is the checkout page so i'll drag this page into my visual studio for opening it okay we don't need any information about the hair we don't need the pre-loader we don't need the address section we don't uh we need the breadcrumb this is the efficient way to use different okay we need this section the shopping cart section we don't need the partner logo we have already copied all the information in our load page we need just these two sections i have copied by using ctrl c and paste it here okay here all the information which we need okay here is our checkout okay this is checkout click here to login we don't have created any login for the user user any user may be come here and provide his information and uh get his order the user don't need to sign up before the uh before making any order in our website so i'm going to remove this here okay billing detail billing detail this is the detail uh which we are seeing the left side okay first name last name company name we can remove some information and we can also add some information for confirmation and here we have to put all the order information all the items which user have purchased okay so this is the first section and this is the second uh this is the first section here and this is the second section of the checkout contents okay we have to fill out this okay first of all uh i will show the user which order content he have purchased okay here are some list items the product is being shown by using simple list item the first item is the top list item and another one is the repetition top item and then the total i'm going to add this this is same process as we have used in our cart okay there are three items in the card we need only one to implement our content okay here is the top the product and the total okay here is the normal uh list item class first one is the title so it is bold and another one is a normal classes so i have to implement this okay i have all the other detail which user have purchased in my shopping cart so i can use my shopping cart here which is uh which is copied in session okay i'm using the resist syntax by using a loop i will call all the item here by using a loop i'll call the for each loop in for each loop double tap to to fire the code snippet item in the collection the collection is my simple collection which is in my session okay i will call this session but before calling the session you have to access the models because all the items in the shopping cart or the session are a type of model which is the card item model so i have to access the model first okay i'm going here to access my model i was using simple syntax by using the uh your application name the main directory of your application the main factory name is e-electronics so here electronics dot models if you have and one model you may specify the further here but i need all the models simply i will insert all the models for simplicity now i have my model here and now i'm going to call my session okay session in my session there is a session element named by card here is my card but card is a generic global variable the most super global variable so i have to cast it into the shopping cart item so i will cast it into a list of list of card items card item list so i can access it here okay all the session item will be come out by converting uh by having morph into a shopping cart item so i have access all the item i will cut it here and paste it here okay now this variable is inside the loop okay how many times the loop will continue it will be repeated okay here we need the name of the product to simply get the name of the product by using our item the loop variable by using the item by using razor syntax item dot product dot name okay and here the price we are dealing in the rupees so i will add a piece and resign now product dot product dot simply using item dot price product dot price we're using sale price here okay how many time the loop will be run all the product will be here so i can refresh this page too see the changes i have done yet okay you can see here we have just added one led tv here and we are seeing the price here but we also need to update the total and subtotals here okay the total will be the total variable i have to access my total i should uh i will declare a global variable here for totally okay i will declare a simple plot type total variable with zero okay now i can access it here and every time the loop will run the total will be updated okay total plus is equal to item dot product dot s price okay here the total will be uploaded every time but the total is in other form i have to cast it into load okay now total will be uploaded into the variable of total and we can declare this we can use this variable here the name of total and again here now i can refresh my page to get some results okay thirty thousands of total thirty thousand if i have added another product then what will happen okay i'm going to product page to add another product i have already added an led tv now i am going to add my laptop here i am here in the checkout page the total is one like 20 000. okay here you can see the led tv and the laptop are both here and the price is one should be same as here okay these are two products or total will be different okay here so you should have to manage the quantity also so you can simply add this product not only the product but also the product multiplied by the quantity user have purchased okay here you can multiply it with a quantity quantity which will become from item dot qt quantity now our total will also be calculated whatever the quantity okay i'm going to right here here two two items and now the total is one like 80 000 proceeding to the checkout and total will be updated as here one simple approach you may also show the quantity here how many quantity are you purchasing here okay i will using this method to multiply okay i'll calling the quantity here quantity at item dot quantity now simple x sign for multiplication simple a list item i can place the x line inside this okay quantity multiplied by the list item okay i'll refresh now 2x led for 30 000 2x laptops for 60 000 and the amount is not sufficient i have to use this price here because the price will be multiplied and i have als so called the multiplied price not only this okay now this will be look like more similar if there is no error here okay float up type one more time okay refresh okay this is considerable represent single email expression flow the races syntax okay done 2x led tvs for 60 000 2x laptops for 120 000 subtotal is 180 000 and all is good okay we can remove because we have already make the payment so i don't need this payment here i will remove this here check payment and also the whole payment methods okay whenever click on this submit button it will submit some data to confirm my order so i will here that can form order okay now let's look pretty good okay confirm order whenever user click on this button all the order details and all the personal detail will be saved to the database and user will be notified with an email that order have been confirmed okay and now i have to make some changing into this form this form has a first name called the fourth input type text id is equal to first i will change all the id attribute into name attribute first name okay because we are changing these input tags are the input to name so we can access them into our controller the first one is the first the last we don't need the company name we don't uh we need country because we are dealing in the pakistan so we don't need the country information here we don't need the postal code okay we need the street address okay the id is street i'll name it to the street down name it to town email name and name phone okay whenever user click on this button the account will be created this is i will comment it here okay i have changed the form a little bit you can see i have only two or three first name last name street address town city email iphone okay this is a simplified form i will process it okay i will go to my controller code and receive all this data okay this is the shop controller but which controller will be responsible to receive all this data so i have to send this data into a specific controller okay this is the form clause i will change it to deep class same as we have done in the create construction i'll using the asp razor form by using html helper i will use the resistant text using i will use the html began using html using will be here using html dot begin form and then i will tell my controller that which action to be performed i will call it the save data save order i have not created this method in my controller i'm going to create this method but i have called it here save order into shop controller okay the method will be post for method dot post okay simple this the all the form will be go inside the braces okay done whenever i will click to this button the type is equal to submit this will submit this form which will invoke the method save order so i have to create this method into my controller this is the shop controller which will deal all our shopping aspects so this is the checkout method i'm going to create another method by same logic which will be save order this will not return any view we will decide it later but it will receive some data it will receive a string type of first for me the for me our this is our checkout 4 means the text box or the input within mr4 it means that the uh the controller will receive the first name which will be written in the first name okay it will receive the full of string type and also the same type of string parameters okay first one is the fourth second one is the last name third one is the for last street down email street town email and the last one is phone we'll remove this extra comma here we don't need another argument here so i have all these information here i have to save into our database uh in every order uh there is a while saving the order there is a relationship which is parent-child relationship every order will have further shopping items in it so i have to deal i will i'm going to show you the database structure of our order for saving the order i have the main table order which will save the basic information of the user it have many column for example in the order date order time auto status customer name customer phone email address order instruction order detail etc here okay this is a static thing and this is a static thing in every order there will be many products so in one order there will be many products so this is a simple master child relationship so to save our child item i have a child table here order detail order details have to order detail id order fid photograph id quantity okay so i have to save this data into multiple uh two tables one table will be responsible to save the main order details another table will be responsible to save the details of the order for example the products in every order there may be many product in one order so we can't save into the main order table this will break our third normalization form so i'm going to save all this information into my database okay first of all uh i have already called the database here db so i will call my db i have to create an object of this main order table so i'm going to have an order of order is equal to new order and this will include the following information also a semicolon here okay i don't have multiple items first one is the customer address customer name so i'm going to have this one by one customer name is equal to the first name so there is a problem the first name and the last name of the customer are two different thing but we have not catered into the database and in our database we have just said that the customer will have a name not the first name and the last name we have not separate column for both of the things so i will concatenate here both of the string types so it can be easily concatenated your the first name and the last name okay first plus last means the simple concatenation but the first first and the last name will be mix up badly so there should be a simple space here so i will add a more plus here and also concatenate our string space here so this will look good okay now customer name will be first name and the last name collection now another argument of the customer phone so i can simply add my phone customer have an address i can add the customer street street is equal to street street and the customer have many things street address and town address both should be concatenated with one okay street plus a simple space and concatenate with the town street aston will be a one value okay now the customer has the customer email so i will assign the email variable to this email a customer have order date i will get the date of my system by using date time dot now dot date okay customer have another details no details here order time i'll simply call the date time again is equal to date time dot now to get the current time now that time turn of the day okay now again the order have another state test so i will add the statement as standing order not ready not delivered but still pending here so whenever we will process this order we'll change the status to uh completed delivered on delivery etc whichever we prefer so now whenever a new order will be entered this will be appending status okay now i will format all this code by using control k control d okay this is our order we have to just simply put all this uh put this object of order into our database so i'll call the db dot order dot and this order okay i'll change the database changes db dot save changing okay i will have saved but now we have to save the every product into our order this is the personal information we have saved but we also have to save we also have to save some other things here we have to save the every item into our shopping cart so in our shopping cart there are items so i should have first of all i have to access all these items so i'll get all this item by using simple a list of card item because every item into my card is a type of card item so i will use the list of god item i will call it god and i will get it from session with the name of card name of session is card and i will cast it to here the shopping cart item simple because item should become out of the session with a type of card item now all the items of the cart are here i have to store every item this means that there are multiple item i can't save one by one there may be one item two items three items so i'm not sure how many time i have to save the card item so i will call a loop a follow which will do this for the loop will be run until every card item is added so i will call it car dot count loop will count the card item and it will run accordingly uh according to the number of card items so every card item should be safe okay i will call the card i will simply have to create an object of card item also so i will create order detail detail is equal to new order detail it will have all two items the order fid means this detail belongs to which order so i have to get the order to which i have to add this information now here is an important thing how can we get the last item we have inserted the item we are having this method and this whole method will be executed simultaneously okay so whenever i have saved this order so my last saved order is the actually order which will be represent this order detail okay so i have to link this to this order so while i'm adding this order there is no other order which is which have a greater greater value here in simple words and said that whatever the order is the last will be the order belongs to this detail so i have to get this order by using the max because in our item we have us our database to auto increment the value so when the last item was 31 the next item will be 32 and the further will be 33 34 34 and the most recent order will be the maximum value of the id so i have to get this maximum value i will call airdb dot order dot max what max max x goes to x dot or drier need another id of maximum value okay i need the product id i need the product id product fid here which will be the our detail uh which will be the card item okay i will simply call the card the value of i dot product dot id id product id prodid now the quantity of the product quantity is equal to i got dot quantity part of this value got off of i value because it is uh there may be many item for every item the quantum will be different so i'm using this i variable here oh this is not the card card art okay our object have been created i just have to put this object into the database by using the same method i have done earlier i will save this method by using dp dot order details dot add this detail done and db dot save changes okay after all this process will be successful we have to show user an important message we have to say user your order have been confirmed an email has been also signed in the next lecture i will show you how can we send the email from here so we have to intimate the user by some ways we may simply put a message for example the static contact but i will make this a little more beautiful and will not return to this view because we don't have any view of the save order save order is only a command so we will return nothing but we will we will take the user to his shopping page or the home page or something so i will return a redirect here redirect the user to the product page so if he wants to purchase another item he will be directly purchased so i will call the redirect to action the action of our products for that this is the action i'm going to send the user after the confirm saving of order this is the order okay now i will integrate a very beautiful alert message which is a pre-built library which is called the sweet alert if you have not already integrate the switch alert notification or we are using the simple alert message which is very boring i'll show you that which is up type this if i less going to less the quantity okay one okay this is the alert message this is very boring and ugly message so i will fix it using this sweet alert i have already a library here the sweet alert and i have also compiled a code for work in mvc this is these are two files which we need for this purpose okay so i'm going to have nothing here just have to integrate this sweet alert into my layout file i'm going to integrate into my layout file so i can access all the information all the alerts on every page which is being used by this layout or which is based on this layout so i'm going to here shared layout we need two steps okay first step is link the street alert library here so i'm going to copy this library first of all to my project the content sweet alert and put it here in the head okay second thing is you have to write a code i have already written a code for this purpose i will show you how this will be worked this is a simple javascript for method it will be only for when the time message has some value okay i will copy this message if you need this code i will be put this code into the command section you can easily take this code from the command section i will paste this code here okay and close my layout file now i can use all the methods here okay return to view section but before it can go to before it can go to saving that uh before it can go too good here before it can go to products page it will show the user a very interesting message the order has saved okay i will simply populate my temp data with the state state means there may be different state the error state the information stage so i'm going to add a success stage okay this date state state is equal to success success and also a message whatever we write here will be shown on this alert message order has confirmed found order has confirmed we have we've already also sent an email a confirmation conformation it will be it will be delivered soon thank you for shopping okay this message will be displayed after all this happen okay i will build my project when the project will be completely completely built okay build succeeded now i can go to my product page and add the products again because i have all built my project again i have to add the products again it will take some time okay here i'm going to add the order one folder proceed to check out showing a bill here confirm order and here i will put some information i can use up with me to populate all this confirm my order and if okay you have seen that a success message order has confirmed we have also sent an email for the confirmation it will be delivered soon thank you for shopping okay this is a state message this is a very beautiful alert this also have some symbol or icon which are missing here i will fix it later this is all we have learned i i have to verify that whether my data have been successfully saved or not so i can wind up my lesson here i've opened my server here okay i will simply windows authentication with my local pc going to verify whether the data is saved or not okay in the databases in the um dbe electronics navy electronics table first of all i'm going to look at the orders table i'm going to have and hit top 2 000 rows 200 okay order have been saved with the order date of this time of days order status is spending the name is concatenated and inserted by the foreign and this is the email the order instruction is null and now i'm going to have to look at whether order detail okay order id you may simply say that order id is equal to 1 and here the order f5 is equal to 1 so this is properly linked with this table okay product is equal to 1 quantity is equal to one the order has been saved successfully uh this is for the now in the later i will show you how you can send an email and then we will go for the reporting session of the sale reports and the purchase reports thank you for watching
Info
Channel: Dev. Khurram Shahzad
Views: 1,417
Rating: undefined out of 5
Keywords:
Id: GJZne4NvuVY
Channel Id: undefined
Length: 47min 2sec (2822 seconds)
Published: Sun Sep 27 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.