Emmmanuel FIADUFE

Emmmanuel FIADUFE

  • 784
  • 1.1k
  • 55.3k

Group product by date and sum up quantity and total sales

Jun 23 2023 7:16 PM

Hello Team, 

Please I need your assistance, in my controller I want to group sales by date and sum of the quantity and total sales

public ActionResult GetAllSalesRecord()
        {
            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.Select(x => new

            {
                SalesDetailId = x.detail.SalesDetailId,
                Quantity = x.detail.Quantity,
                ProductId = x.detail.ProductId,
                ProductName = x.detail.tblProduct.ProductName,
                SalesId = x.Sales.SalesId,
                OrderDate = x.Sales.OrderDate,
                TotalAmount = x.Sales.TotalAmount
            }).ToList();
            return Json(modifiedData, JsonRequestBehavior.AllowGet);
        }


Answers (4)