Emmmanuel FIADUFE

Emmmanuel FIADUFE

  • 782
  • 1.1k
  • 55.7k

Monthly Sales Count

Nov 21 2023 8:52 AM

Hello Team, 

Please I want to get sales count by month on my bar graph

// This is to get sales performance by Month on the bar graph

  public JsonResult GetSalesPerformanceByType()
   {         
            ASPNETMASTERPOSTEntities db = new ASPNETMASTERPOSTEntities();
            var previousYear = (DateTime.Now.Year - 1);
            var sales = db.tblSales
                .Join(db.tblSalesDetails, s => s.SalesId, sd => sd.SalesId, (s, sd) => new { sale = s, saleDetail = sd })
                .Join(db.tblProducts, sd => sd.saleDetail.ProductId, p => p.ProductId, (sd, p) => new { sale = sd, product = p })
                .ToList();
            var salesBypercentageByProduct = (from s in sales
                                              where DateTime.Parse(s.sale.sale.OrderDate).Year > previousYear
                                              group s by new { s.sale.saleDetail.ProductId, s.product.ProductName } into gs
                                              select new { Name = gs.Key.ProductName  }).ToArray();

            
            return Json(new { Names = Names}, JsonRequestBehavior.AllowGet);
        }


Answers (3)