Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [HttpPost]
- [Route("DataTableList")]
- public async Task<ActionResult> PostDataTableList(
- [FromForm] Dictionary<string, string>[] columns,
- [FromForm] int draw,
- [FromForm] int start,
- [FromForm] int length,
- [FromForm] Dictionary<string, string>[] order,
- [FromForm] Dictionary<string, string> search,
- [FromForm] string productCategoryId
- )
- {
- var orderCol = columns[Int16.Parse(order[0]["column"])]["data"];
- var orderDirection = order[0]["dir"].ToUpper();
- if (search["value"] == null) search["value"] = "";
- var searchValue = search["value"].ToLower();
- var all =
- from a in this.repo.db.Product
- join b in this.repo.db.ProductCategory
- on a.ProductCategoryId equals b.Id into ab
- from b in ab.DefaultIfEmpty()
- join c in this.repo.db.Lookup
- on a.UomId equals c.Id into ac
- from c in ac.DefaultIfEmpty()
- join d in this.repo.db.Lookup
- on a.WeightUomId equals d.Id into ad
- from d in ad.DefaultIfEmpty()
- join e in this.repo.db.Lookup
- on a.PurchaseCurrencyId equals e.Id into ae
- from e in ae.DefaultIfEmpty()
- join f in this.repo.db.Lookup
- on a.SellingCurrencyId equals f.Id into af
- from f in af.DefaultIfEmpty()
- where
- a.RowStatus == 1 && (
- a.Code.ToLower().Contains(searchValue) ||
- a.Name.ToLower().Contains(searchValue) ||
- b.Name.ToLower().Contains(searchValue)
- )
- select new
- {
- a.Id,
- a.Code,
- a.Name,
- a.SupplierProductCode,
- a.SupplierProductName,
- a.Alias,
- productcode = b.Code,
- a.Description,
- a.Specification,
- uomid = c.Name,
- a.Weight,
- wuomid = d.Name,
- purchaseCurrencyid = e.Name,
- a.PurchasePrice,
- sellingcurrencyid = f.Name,
- a.SellingPrice,
- a.MinStock,
- a.MaxStock,
- a.ProductCategoryId
- };
- if (productCategoryId != null && productCategoryId != "") all = all.Where(x => x.ProductCategoryId == Int16.Parse(productCategoryId));
- var data = await all
- .OrderBy(orderCol + " " + orderDirection)
- .Skip(start)
- .Take(length)
- .ToListAsync();
- return Json(new {
- draw = draw,
- iTotalRecords = all.Count(),
- iTotalDisplayRecords = all.Count(),
- aaData = data
- });
- }
Add Comment
Please, Sign In to add comment