public async Task <JsonResult> SubmitCheckout(CheckoutModel model)
 {
     try
     {
         if (ModelState.IsValid)
         {
             var order = await new OrderDAO().AddOrder(model.CustomerName, model.CustomerAddress, model.CustomerPhone, await GetTotal());
             if (order != 0)
             {
                 try
                 {
                     var orderdetail = new OrderDetailDAO();
                     foreach (var item in (List <CartSession>)Session["cart"])
                     {
                         await orderdetail.AddOrderDetail(order, item.ProductID, item.Quantity);
                     }
                     Session["cart"] = null;
                     return(Json(new { Success = true, ID = order }, JsonRequestBehavior.AllowGet));
                 }
                 catch
                 {
                     var result = await new OrderDAO().DeleteOrder(order);
                     return(Json(new { Success = false, error = "error creating order details" }, JsonRequestBehavior.AllowGet));
                 }
             }
             return(Json(new { Success = false }, JsonRequestBehavior.AllowGet));
         }
         return(Json(new { Success = false }, JsonRequestBehavior.AllowGet));
     }
     catch
     {
         return(Json(new { Success = false }, JsonRequestBehavior.AllowGet));
     }
 }
 public async Task <JsonResult> SubmitCheckoutCustomer(CheckoutModel model)
 {
     try
     {
         var customer = await new CustomerDAO().LoadByUsername(HttpContext.User.Identity.Name);
         var order    = await new OrderDAO().AddOrderCustomer(customer.CustomerID, model.CustomerName, model.CustomerAddress, model.CustomerPhone, await GetTotal());
         if (order != 0)
         {
             try
             {
                 var orderdetail = new OrderDetailDAO();
                 foreach (var item in (List <CartItemModel>)Session["cart"])
                 {
                     await orderdetail.AddOrderDetail(order, item.product.ProductID, item.quantity);
                 }
                 Session["cart"] = null;
                 return(Json(new { Success = true, ID = order }, JsonRequestBehavior.AllowGet));
             }
             catch
             {
                 var result = await new OrderDAO().DeleteOrder(order);
                 return(Json(new { Success = false, error = "error creating order details" }, JsonRequestBehavior.AllowGet));
             }
         }
         return(Json(new { Success = false }, JsonRequestBehavior.AllowGet));
     }
     catch
     {
         return(Json(new { Success = false }, JsonRequestBehavior.AllowGet));
     }
 }
 public async Task <JsonResult> SubmitCheckout(CheckoutModel model)
 {
     try
     {
         if (ModelState.IsValid)
         {
             var orderid = await new OrderDAO().AddOrder(model.CustomerName, model.CustomerAddress, model.CustomerPhone, await GetTotal());
             if (orderid != 0)
             {
                 try
                 {
                     var orderdetail = new OrderDetailDAO();
                     foreach (var item in (List <CartItemModel>)Session["cart"])
                     {
                         await orderdetail.AddOrderDetail(orderid, item.product.ProductID, item.quantity);
                     }
                     Session["cart"] = null;
                     return(Json(new JsonStatus()
                     {
                         Status = true,
                         Message = orderid.ToString()
                     }, JsonRequestBehavior.AllowGet));
                     //return Json(new { Success = true, ID = orderid }, JsonRequestBehavior.AllowGet);
                 }
                 catch
                 {
                     var result = await new OrderDAO().DeleteOrder(orderid);
                     return(Json(new JsonStatus()
                     {
                         Status = false,
                         Message = "error creating order details"
                     }, JsonRequestBehavior.AllowGet));
                     //return Json(new { Success = false, error = "error creating order details" }, JsonRequestBehavior.AllowGet);
                 }
             }
             return(Json(new JsonStatus()
             {
                 Status = false,
                 Message = "Fail create order"
             }, JsonRequestBehavior.AllowGet));
         }
         return(Json(new JsonStatus()
         {
             Status = false,
             Message = "Model State no valid"
         }, JsonRequestBehavior.AllowGet));
     }
     catch
     {
         return(Json(new JsonStatus()
         {
             Status = false,
             Message = "Error"
         }, JsonRequestBehavior.AllowGet));
     }
 }