Online Restaurant Website Part 41 Recent Orders

      Online Restaurant Website Part 41 Recent Orders

Hi, Dear's here we learn how to implement "Pizza Restaurant Drink" Website in Visual Studio using C# ASP.NET MVC. Ilyasoft software company provide full project step by step training on our YouTube Channel ilyasoft software company so now subscribe, share and like for more project base tutorials



In this video we are going to finish place order for more details click here: watch vedio

First we are going to database and create View for get all user Orders, in below diagram all tables are show, in video we will discuss how to create v_Orders to get recent orders:



> This is the Code of v_Orders: (if you want you can create by code also)

CREATE VIEW [dbo].[v_Orders]
AS
SELECT        dbo.OrderTable.OrderID, dbo.OrderTable.OrderBy_UserID AS Customer_UserID, dbo.UserTable.UserName AS Customer_UserName, dbo.OrderTable.OrderDateTime AS Order_DateTime, dbo.OrderTable.OrderTypeID, 
                         dbo.OrderTypeTable.OrderType, dbo.OrderTable.OrderReceivedBy_FullName AS Customer_FullName, dbo.OrderTable.OrderReceivedBy_ContactNo AS Customer_ContactNo, dbo.OrderTable.OrderStatusID, 
                         dbo.OrderStatusTable.OrderStatus, dbo.OrderTable.Description, dbo.OrderTable.ProcessBy_UserID, ProcessUserTable.UserName AS ProcessUserName, dbo.OrderTable.OrderPaymentID, 
                         dbo.OrderPaymentTable.OrderPaymentStatus, dbo.OrderTable.DeliveryAddress_UserAddressID AS DeliveryAddressID, dbo.UserAddressTable.FullAddress AS DeliveryAddress
FROM            dbo.OrderTable INNER JOIN
                         dbo.OrderTypeTable ON dbo.OrderTable.OrderTypeID = dbo.OrderTypeTable.OrderTypeID INNER JOIN
                         dbo.UserAddressTable ON dbo.OrderTable.DeliveryAddress_UserAddressID = dbo.UserAddressTable.UserAddressID INNER JOIN
                         dbo.UserTable ON dbo.OrderTable.OrderBy_UserID = dbo.UserTable.UserID INNER JOIN
                         dbo.OrderStatusTable ON dbo.OrderTable.OrderStatusID = dbo.OrderStatusTable.OrderStatusID INNER JOIN
                         dbo.OrderPaymentTable ON dbo.OrderTable.OrderPaymentID = dbo.OrderPaymentTable.OrderPaymentID INNER JOIN
                         dbo.UserTable AS ProcessUserTable ON dbo.OrderTable.ProcessBy_UserID = ProcessUserTable.UserID
GO


Next go to project and update Data_Model. How? watch video. 

Next create OrderDetailsMV Model to store recent orders item and deals details. 

OrderDetailsMV Model Code: 

 public class OrderDetailsMV
 {
     public int ItemDetailID { get; set; }
     public int StockItemID { get; set; }
     public string StockItemTitle { get; set; }
     public string StockItemCategory { get; set; }
     public string ItemPhotoPath { get; set; }
     public string ItemSize { get; set; }
     public double UnitPrice { get; set; }
     public int Qty { get; set; }
     public double ItemCost { get; set; }
     public string ItemType { get; set; }
 }

Next create CustomerOrdersMV Model to store all recent orders.

> CustomerOrdersMV Model Code: 

    public class CustomerOrdersMV
    {
        public int OrderID { get; set; }
        public int Customer_UserID { get; set; }
        public string Customer_UserName { get; set; }
        public System.DateTime Order_DateTime { get; set; }
        public int OrderTypeID { get; set; }
        public string OrderType { get; set; }
        public string Customer_FullName { get; set; }
        public string Customer_ContactNo { get; set; }
        public int OrderStatusID { get; set; }
        public string OrderStatus { get; set; }
        public string Description { get; set; }
        public int ProcessBy_UserID { get; set; }
        public string ProcessUserName { get; set; }
        public int OrderPaymentID { get; set; }
        public string OrderPaymentStatus { get; set; }
        public int DeliveryAddressID { get; set; }
        public string DeliveryAddress { get; set; }
        public double TotalCost { get; set; }

        public List<OrderDetailsMV> OrderDetails { get; set; }
    }

Next go to DashboardMV Model 

Add as property of List<CustomerOrdersMV> in DashboardMV Model, to store recent orders.

> Property Code: 

    public virtual List<CustomerOrdersMV> AllOrders { get; set; }

Next Create GetUserOrders Method in DashboardMV to get all recent orders from database, in store in AllOrders Property.
Code:>
 public void GetUserOrders(int userid)
{
    AllOrders = new List<CustomerOrdersMV>();
    var orders = db.v_Orders.Where(u => u.Customer_UserID == userid).ToList();
    foreach (var item in orders)
    {
        var customerorder = new CustomerOrdersMV();
        customerorder.OrderID = item.OrderID;
        customerorder.Customer_UserID = item.Customer_UserID;
        customerorder.Customer_UserName = item.Customer_UserName;
        customerorder.Order_DateTime = DateTime.Now;
        customerorder.OrderTypeID = item.OrderTypeID;
        customerorder.OrderType = item.OrderType;
        customerorder.Customer_FullName = item.Customer_FullName;
        customerorder.Customer_ContactNo = item.Customer_ContactNo;
        customerorder.OrderStatusID = item.OrderStatusID;
        customerorder.OrderStatus = item.OrderStatus;
        customerorder.Description = item.Description;
        customerorder.ProcessBy_UserID = item.ProcessBy_UserID;
        customerorder.ProcessUserName = item.ProcessUserName;
        customerorder.OrderPaymentID = item.OrderPaymentID;
        customerorder.OrderPaymentStatus = item.OrderPaymentStatus;
        customerorder.DeliveryAddressID = item.DeliveryAddressID;
        customerorder.DeliveryAddress = item.DeliveryAddress;
        customerorder.OrderDetails = new List<OrderDetailsMV>();
        foreach (var order_item in db.OrderItemDetailTables.Where(i => i.OrderID == item.OrderID).ToList())
        {
            
            var stockitem = db.StockItemTables.Find(order_item.StockItemID);
            customerorder.OrderDetails.Add(new OrderDetailsMV()
            {
                ItemDetailID = order_item.OrderItemDetailID,
                StockItemID = order_item.StockItemID,
                StockItemTitle = stockitem.StockItemTitle,
                StockItemCategory = stockitem.StockItemCategoryTable.StockItemCategory,
                ItemPhotoPath = stockitem.ItemPhotoPath,
                ItemSize = stockitem.ItemSize,
                UnitPrice = stockitem.UnitPrice,
                Qty = order_item.Qty,
                ItemCost = stockitem.UnitPrice * order_item.Qty,
                ItemType = "item"
            });
            customerorder.TotalCost += stockitem.UnitPrice * order_item.Qty;
        }

        foreach (var order_deal in db.OrderDealDetailTables.Where(d => d.OrderID == item.OrderID).ToList())
        {
            var stockdeal = db.StockDealTables.Find(order_deal.StockDealID);
            customerorder.OrderDetails.Add(new OrderDetailsMV()
            {
                ItemDetailID = order_deal.OrderDealDetailID,
                StockItemID = order_deal.StockDealID,
                StockItemTitle = stockdeal.StockDealTitle,
                StockItemCategory = "Deal",
                ItemPhotoPath = stockdeal.DealPhoto,
                ItemSize = "Normal",
                UnitPrice = stockdeal.DealPrice,
                Qty = order_deal.Qty,
                ItemCost = stockdeal.DealPrice * order_deal.Qty,
                ItemType = "Deal"
            });
            customerorder.TotalCost += stockdeal.DealPrice * order_deal.Qty;
        }
        AllOrders.Add(customerorder);
    }


}

Next GetUserOrders method call in DashboardMV Constructor, 
Code:> 
 GetUserOrders(user.UserID);

Next go to userController and open Dashboard View.
Add the below code to show recent order status. 

Code: 
<div class="most-recent-order">
    <h5>Recent Orders</h5>
    @foreach (var order in @Model.AllOrders)
    {
        <div class="field-entry">
            <div class="row">
                <div class="col-5">
                    <p>PIR-@order.OrderID</p>
                </div>
                <div class="col">
                    @if (order.OrderStatusID <= 4)
                    {
                        <p class="confirmed"><i class="icofont icofont-check"></i>@order.OrderStatus</p>
                    }
                    else if (order.OrderStatusID >= 5)
                    {
                        <p class="failed"><i class="icofont icofont-close"></i>@order.OrderStatus</p>
                    }
                </div>
                <div class="col text-right">
                    <a href="#history">Detail</a>
                </div>
            </div>
        </div>
    }
</div>
  

once all the above step is done, run the application.

 


Comments