Emmmanuel FIADUFE

Emmmanuel FIADUFE

  • 839
  • 856
  • 38.1k

Angular controller not deleting data from sqlserver database

Jun 29 2023 3:43 PM

Hello Team,

In my angularJs controller data is not deleting from the database.

 

 
$scope.DeleteInvoiceList = function(SalesId,SalesDetailId){
            // Need to implement 
            swal({
                title: 'Do you want to delete Record?',
                showCancelButton: true,
                showConfirmButton: true,
                confirmButtonText: 'Yes Delete',
                cancelButtonText: 'No pls cancel',
                confirmButtonClass: 'btn btn-success',
                cancelButtonClass: 'btn btn-danger',
                type: 'warning',
                buttonsStyling: false
            }).then(
            function (isConfirm) {
                // Called if you click Yes.
                if (isConfirm) {
                    // Make Ajax call.
                    $.get("/Home/DeleteInvoiceList", { SalesDetailId: SalesDetailId,  SalesId:SalesId}, function (res) {
                        debugger;
                        if (res) {
                            dataTable.ajax.reload();                                          
                        }
                        
                    })
                    swal('Confirm', '1 Record deleted successfully', 'success');
                    //dataTable.ajax.reload();
                    
                }
            }, function (no) {
                // Called if you click No.
                if (no == 'cancel') {
                    swal('Cancelled', '', 'error');
                }

            });
        }

 

HOME CONTROLLER

 public ActionResult DeleteInvoiceList(int SalesDetailId, int SalesId, int ProductId = 0)
        {
            try
            {
               ASPNETMASTERPOSTEntities db = new ASPNETMASTERPOSTEntities();
                var salesDetails = db.tblSalesDetails.Where(a => a.SalesDetailId == SalesDetailId).ToList();
                var sales = db.tblSales.Where(a => a.SalesId == SalesId).FirstOrDefault();

                      if (salesDetails != null)
                      db.tblSalesDetails.Remove(item);                     
                if (sales != null)
                    db.tblSales.Remove(sales);              
                db.SaveChanges();
                return Json(true, JsonRequestBehavior.AllowGet);
            }
            catch (Exception)
            {
                return Json(false, JsonRequestBehavior.AllowGet);
            }
        }


Answers (3)