Online Restaurant Website Part 46 Order Confirmed

  Online Restaurant Website Part 46 Order Confirmed

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 learn how to confirmed order for more details click here: watch vedio

for order confirmation we use javascript method using jquery library.  

Now open OrderController and create method for updated order, once updated order method create successfully then we call this method on confirmed button through javascript function to confirmed order. 

So the below code for Updated Order Method. 

> Add in OrderController 

public ActionResult Update_Order(int? orderid,int? statusid)
{
    bool result = false;
    using (var transaction = Db.Database.BeginTransaction())
    {
        try
        {
            var item = Db.OrderTables.Where(o => o.OrderID == orderid).FirstOrDefault();
            if (item != null)
            {
                item.OrderStatusID = (int)statusid;
                Db.Entry(item).State = System.Data.Entity.EntityState.Modified;
                Db.SaveChanges();
            }
            result = true;
            transaction.Commit();
            return Json(result, JsonRequestBehavior.AllowGet);
        }
        catch (Exception ex)
        {
            result = false;
            transaction.Rollback();
            return Json(result, JsonRequestBehavior.AllowGet);
        }
    }
}

so go to Customer Order view and add below some code step by step to perform order confirmation .  

> Customer View Code. 

Step 1: In this step we get userid and usertypeid from session, add in view "title section". 

     int userid = 0, usertypeid = 0;
    if (!string.IsNullOrEmpty(Convert.ToString(Session["UserID"])))
    {
        int.TryParse(Convert.ToString(Session["UserID"]), out userid);
    }
    if (!string.IsNullOrEmpty(Convert.ToString(Session["UserTypeID"])))
    {
        int.TryParse(Convert.ToString(Session["UserTypeID"]), out usertypeid);
    }
  

Step 2: In this step we are going to add some button to call order_update method through java script method. Buttons are "Order Cancel Button", "Order Confirm Button" , "On-Way Button ",  "Order Delivered Button" and so on. 

      <div class="col-md-4 col-sm-3 text-right">
     @if (order.OrderStatusID == 1) // Pending Status
     {
         <p class="confirmed"><i class="icofont icofont-check"></i>@order.OrderStatus</p>
         <button type="button" class="btn btn-theme btn-md" onclick="cancelOrder(@order.OrderID)">
             <i class="icofont icofont-close-line"></i>Cancel
         </button>
         <br>
         <button type="button" class="btn btn-theme btn-md" onclick="updateOrder(@order.OrderID,2)">
             <i class="icofont icofont-close-line"></i>Confirmed
         </button>
         <br>

     }
     else if (order.OrderStatusID == 2) // Confrimed Status
     {
         <p class="confirmed"><i class="icofont icofont-check"></i>@order.OrderStatus</p>
         <button type="button" class="btn btn-theme btn-md" onclick="updateOrder(@order.OrderID,3)">
             <i class="icofont icofont-close-line"></i>On-Way
         </button>
         <br>
         <button type="button" class="btn btn-theme btn-md" onclick="updateOrder(@order.OrderID,4)">
             <i class="icofont icofont-close-line"></i>Delivered
         </button>

     }
     else if (order.OrderStatusID == 3) // On-Way Status
     {
         <p class="confirmed"><i class="icofont icofont-check"></i>@order.OrderStatus</p>
         <button type="button" class="btn btn-theme btn-md" onclick="updateOrder(@order.OrderID,4)">
             <i class="icofont icofont-close-line"></i>Delivered
         </button>
         <button type="button" class="btn btn-theme btn-md" onclick="updateOrder(@order.OrderID,5)">
             <i class="icofont icofont-close-line"></i>Delivery Failed
         </button>
         <br>
         <button type="button" class="btn btn-theme btn-md" onclick="updateOrder(@order.OrderID,7)">
             <i class="icofont icofont-close-line"></i>Payment Failed
         </button>

     }
     else if (order.OrderStatusID == 7) // On-Way Status
     {
         <p class="confirmed"><i class="icofont icofont-check"></i>@order.OrderStatus</p>
         <button type="button" class="btn btn-theme btn-md" onclick="updateOrder(@order.OrderID,4)">
             <i class="icofont icofont-close-line"></i>Delivered
         </button>
         <button type="button" class="btn btn-theme btn-md" onclick="updateOrder(@order.OrderID,5)">
             <i class="icofont icofont-close-line"></i>Delivery Failed
         </button>
         <br>
         <button type="button" class="btn btn-theme btn-md" onclick="updateOrder(@order.OrderID,7)">
             <i class="icofont icofont-close-line"></i>Payment Failed
         </button>

     }
     else if (order.OrderStatusID == 4)
     {
         <p class="confirmed"><i class="icofont icofont-close"></i>@order.OrderStatus</p>
     }
     else if (order.OrderStatusID >= 5)
     {
         <p class="failed"><i class="icofont icofont-close"></i>@order.OrderStatus</p>
     }

 </div>

Step 3: Add some javascript code to call Update_Order Action using json library. code is below.  

     function updateOrder(orderid,statusid) {
    var url = "/Order/Update_Order?orderid=" + orderid + "&statusid=" + statusid
    $.ajax({
        url: url,
        type: 'GET',
        dataType: 'json',
        // we set cache: false because GET requests are often cached by browsers
        // IE is particularly aggressive in that respect
        cache: false,
        data: {},
        success: function (result) {
            if (result == true) {
                location.reload();
            }
            else {
                alert("Plz login and Try-Again!");
            }
        }
    });
}

Now call javascript function on onclick event of all buttons. How? show in code below.   

> Code

onclick="updateOrder(@order.OrderID,4)" 

 and also update load more order section  code 

   <div class="text-center load-more">

       @if (Model.Count() > 0)

       {

       }

       else

       {

           <a class="btn btn-theme btn-md btn-wide" href="#">No Orders</a>

       }

   </div> 

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

 







Comments