Online Restaurant Website Part 43 Order Cancellation

 Online Restaurant Website Part 43 Order Cancellation

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 cancel order for more details click here: watch vedio

for order cancellation we use javascript method using jquery library.  

Now open OrderController and create method for cancellation order, one cancellation method create successfully then we call this method on cancel button through javascript function to cancel order. 

So the below code for Cancel Order Method. 

> Code

public ActionResult Cancel_Order(int? orderid)
{
    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 = 6;
                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 dashboard view and add below javascript funcation.  

> Code

<script type="text/javascript">

    function cancelOrder(orderid) {
        var url = "/Order/Cancel_Order?orderid=" + orderid;
        $.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!");
                }
            }
        });
    }
</script>
  

Now call javascript function on onclick event of cancel order button. How? show in code below.   

> Code

onclick="cancelOrder(@order.OrderID)"

 

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

 






Comments