0

I'm getting a list in my angular.js file (EditDeleteItem.js) which I'm making based on the selected table name.

The function to send my list is as below:-

$scope.SaveTblRecord = function (list) {
        //alert(JSON.stringify($scope.employeeList));

        $scope.FetchTableName();
        //var Data = $.param({ TblData: $scope.MyTblDataList });
        var itemList = [];
        angular.forEach(list, function (value, key) {
            if (list[key].selected) {
                itemList.push(list[key].selected);
            }
        });

        $scope.ItemsList = [];
        $scope.ItemsList = itemList;

        $http({
            method: "Post",
            url: "/Admin/SaveTblData",
            data: $scope.ItemsList,
        }).success(function (data) {
            $scope.GetTblData($scope.TempName);
        }).error(function (err) {
            alert(err.Message);
        })
    };//SaveTblRecord

Now in my Controller I want to fetch that list based on the selected table name but I can't do it :-

public JsonResult SaveTblData(List<LocationTbl> NewTblList)    //Need To Have TableName here instead of LocationTbl so that selected table name list is fetched.
    {

        string MyTableName = Convert.ToString(TempData["TableName"]);

        try
        {
            if (NewTblList == null)
            {
                return new JsonResult { Data = "Empty Selection", JsonRequestBehavior = JsonRequestBehavior.AllowGet };
            }
            else {
                using (EBContext db = new EBContext())
                {
                    bool results = false;

                    Type tableType = typeof(CourseDesc);
                    switch (MyTableName)
                    {
                        //case "CourseTbl":
                        //    for (int i = 0; i < NewTblList.Count; i++)
                        //    {
                        //        var CtObj = NewTblList[i];
                        //        CourseTbl ct = db.Courses.AsNoTracking().FirstOrDefault(x => x.ID == CtObj.ID);
                        //        results = UtilityMethods<CourseTbl, int>.EditEntity(db, CtObj);
                        //    }
                        //    break;
                        //case "CourseDescTbl":
                        //    for (int i = 0; i < NewTblList.Count; i++)
                        //    {
                        //        var CdtObj = NewTblList[i];
                        //        CourseDesc cd = db.CourseDesc.AsNoTracking().FirstOrDefault(x => x.ID == CdtObj.ID);
                        //        results = UtilityMethods<CourseDesc, int>.EditEntity(db, CdtObj);
                        //    }
                        //    break;
                        //case "CourseSubDesc":
                        //    for (int i = 0; i < NewTblList.Count; i++)
                        //    {
                        //        var CsdObj = NewTblList[i];
                        //        CourseSubDesc csd = db.CourseSubDesc.AsNoTracking().FirstOrDefault(x => x.ID == CsdObj.ID);
                        //        results = UtilityMethods<CourseSubDesc, int>.EditEntity(db, CsdObj);
                        //    }
                        //    break;
                        //case "InternTbl":
                        //    for (int i = 0; i < NewTblList.Count; i++)
                        //    {
                        //        var ItObj = NewTblList[i];
                        //        InternShip It = db.Interns.AsNoTracking().FirstOrDefault(x => x.ID == ItObj.ID);
                        //        results = UtilityMethods<InternShip, int>.EditEntity(db, ItObj);
                        //    }
                        //    break;
                        case "LocationTbl":
                            for (int i = 0; i < NewTblList.Count; i++)
                            {
                                var LtObj = NewTblList[i];
                                LocationTbl lt = db.Loc.AsNoTracking().FirstOrDefault(x => x.ID == LtObj.ID);
                                results = UtilityMethods<LocationTbl, int>.EditEntity(db, LtObj);
                            }
                            break;
                    }

                    var resultList = new List<object>();
                    foreach (var item in db.Set(tableType))
                    {
                        resultList.Add(item);
                    }

                    return new JsonResult { Data = resultList, JsonRequestBehavior = JsonRequestBehavior.AllowGet };
                }

            }

        }
        catch (Exception ex)
        {

            return new JsonResult { Data = ex.Message, JsonRequestBehavior = JsonRequestBehavior.AllowGet };
        }
    }

I've been searching the internet for a while and found some related links like Link1

and Link2

But I can't find solution to my problem. Please HELP!!

Deepak
  • 376
  • 6
  • 23

0 Answers0