dimaspermana

Untitled

Apr 8th, 2020
652
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.13 KB | None | 0 0
  1. [HttpPost]
  2.         [Route("DataTableList")]
  3.         public async Task<ActionResult> PostDataTableList(
  4.             [FromForm] Dictionary<string, string>[] columns,
  5.             [FromForm] int draw,
  6.             [FromForm] int start,
  7.             [FromForm] int length,
  8.             [FromForm] Dictionary<string, string>[] order,
  9.             [FromForm] Dictionary<string, string> search,
  10.             [FromForm] string productCategoryId
  11.         )
  12.         {
  13.             var orderCol = columns[Int16.Parse(order[0]["column"])]["data"];
  14.             var orderDirection = order[0]["dir"].ToUpper();
  15.             if (search["value"] == null) search["value"] = "";
  16.             var searchValue = search["value"].ToLower();
  17.  
  18.             var all =
  19.                 from a in this.repo.db.Product
  20.                 join b in this.repo.db.ProductCategory
  21.                     on a.ProductCategoryId equals b.Id into ab
  22.                 from b in ab.DefaultIfEmpty()
  23.                 join c in this.repo.db.Lookup
  24.                     on a.UomId equals c.Id into ac
  25.                 from c in ac.DefaultIfEmpty()
  26.                 join d in this.repo.db.Lookup
  27.                    on a.WeightUomId equals d.Id into ad
  28.                 from d in ad.DefaultIfEmpty()
  29.                 join e in this.repo.db.Lookup
  30.                   on a.PurchaseCurrencyId equals e.Id into ae
  31.                 from e in ae.DefaultIfEmpty()
  32.                 join f in this.repo.db.Lookup
  33.                  on a.SellingCurrencyId equals f.Id into af
  34.                 from f in af.DefaultIfEmpty()
  35.  
  36.                 where
  37.                     a.RowStatus == 1 && (
  38.                         a.Code.ToLower().Contains(searchValue) ||
  39.                         a.Name.ToLower().Contains(searchValue) ||
  40.                         b.Name.ToLower().Contains(searchValue)
  41.                     )
  42.                 select new
  43.                 {
  44.                     a.Id,
  45.                     a.Code,
  46.                     a.Name,
  47.                     a.SupplierProductCode,
  48.                     a.SupplierProductName,
  49.                     a.Alias,
  50.                     productcode = b.Code,
  51.                     a.Description,
  52.                     a.Specification,
  53.                     uomid = c.Name,
  54.                     a.Weight,
  55.                     wuomid = d.Name,
  56.                     purchaseCurrencyid = e.Name,
  57.                     a.PurchasePrice,
  58.                     sellingcurrencyid = f.Name,
  59.                     a.SellingPrice,
  60.                     a.MinStock,
  61.                     a.MaxStock,
  62.                     a.ProductCategoryId
  63.  
  64.  
  65.  
  66.                 };
  67.  
  68.             if (productCategoryId != null && productCategoryId != "") all = all.Where(x => x.ProductCategoryId == Int16.Parse(productCategoryId));
  69.  
  70.             var data = await all
  71.                 .OrderBy(orderCol + " " + orderDirection)
  72.                 .Skip(start)
  73.                 .Take(length)
  74.                 .ToListAsync();
  75.  
  76.             return Json(new {
  77.                 draw = draw,
  78.                 iTotalRecords = all.Count(),
  79.                 iTotalDisplayRecords = all.Count(),
  80.                 aaData = data
  81.             });
  82.         }
Add Comment
Please, Sign In to add comment