public async Task <IActionResult> Edit(int id, [Bind("Id,ProductId,Qty,AddressId,AccountId,OrderStatus")] Purchase purchase)
        {
            if (id != purchase.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _repository.UpdatePurchase(purchase);
                    await _repository.Save();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!await PurchaseExists(purchase.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["ProductId"] = new SelectList(await _productServ.GetAll(), "Id", "Id", purchase.ProductId);
            return(View(purchase));
        }
 public ActionResult AddOrEdit(dtoPurchase dtoPurchase)
 {
     try
     {
         if (dtoPurchase.PurchaseId == 0)
         {
             _purchaseRepo.SavePurchase(dtoPurchase);
             return(Json(new { success = true, message = "Saved Successfully" }, JsonRequestBehavior.AllowGet));
         }
         else
         {
             _purchaseRepo.UpdatePurchase(dtoPurchase);
             return(Json(new { success = true, message = "Updated Successfully" }, JsonRequestBehavior.AllowGet));
         }
     }
     catch (Exception e)
     {
         return(Json(new { success = false, message = "Error in " + (dtoPurchase.PurchaseId == 0 ? "saving" : "updation") + "\n" + e.Message }, JsonRequestBehavior.AllowGet));
     }
 }