Emmmanuel FIADUFE

Emmmanuel FIADUFE

  • 749
  • 1.2k
  • 58.5k

Selecting dataTable's data between date range

Jul 10 2023 4:27 PM

Hellow Team,

In my dataTable I want to select the data between date rage that will as well display product quantity and total amount at the footer.

  public ActionResult GetTopTenBestSellingProducts()
        {
           
            ASPNETMASTERPOSTEntities db = new ASPNETMASTERPOSTEntities();
            var dataList = db.tblSales.Join(
               db.tblSalesDetails,
               sales => sales.SalesId,
               detail => detail.SalesId,
               (sales, detail) => new { Sales = sales, detail = detail });
            var modifiedData = dataList.GroupBy(x => new { x.Sales.OrderDate, x.detail.ProductId }).Select(x => new BestSellingProducts

            {
                SalesDetailId = x.FirstOrDefault().detail.SalesDetailId,
                Quantity = x.Sum(s => s.detail.Quantity),
                ProductId = x.Key.ProductId,
                ProductName = x.FirstOrDefault().detail.tblProduct.ProductName,
                SalesId = x.FirstOrDefault().Sales.SalesId,
                strOrderDate = x.Key.OrderDate,
                TotalAmount = x.Sum(s => s.Sales.TotalAmount)
            }).Take(10).ToList(); 

          
            return Json(responseData, JsonRequestBehavior.AllowGet);
        }


Answers (5)