Saturday, June 8, 2024

Data-Table to List

 Auto increment in DataTable to List





public JsonResult GetProductCategoryList()

        {

            try

            {

                List<ProductCategoryViewModel> List_ProdCatViewModel = new List<ProductCategoryViewModel>();


                //var param = new { CompanyId = LoggedInCompId };

                //var CategoryList = productCategoryService.GetAll().Where(x => x.IsRemoved == false);

                var CategoryList = spQueryService.GetDataWithoutParameter("SP_Get_ProductCategoryListWithType");

                var count = 0;


                List_ProdCatViewModel = CategoryList.Tables[0].AsEnumerable()

                .Select(row => new ProductCategoryViewModel

                {

                    rowSl = (++count).ToString(),

                    ProdCatId = row.Field<int>("ProdCatId"),

                    ProdTypeName = row.Field<string>("ProdTypeName"),

                    ProdCatName = row.Field<string>("ProdCatName"),

                    ProdCatNameOther = row.Field<string>("ProdCatNameOther"),

                    DepriciateValue = row.Field<decimal?>("DepriciateValue"),


                }).ToList();


                return Json(List_ProdCatViewModel, JsonRequestBehavior.AllowGet);

            }

            catch (Exception ex)

            {

                return Json(new { Result = "ERROR", Message = ex.Message }, JsonRequestBehavior.AllowGet);

            }

        }

No comments:

Post a Comment

Screen Record

 Windows Screen Record WindowsKey+ Alt + R Recording Starts.