Hello Team,
Please I want to show daily sales on my mvc application dashboard by date, kindly assist
public JsonResult GetDashboardData()
{
ASPNETMASTERPOSTEntities db = new ASPNETMASTERPOSTEntities();
var currentDate = DateTime.Now.Date.ToString("dd-MMM-yyyy");
return Json(JsonRequestBehavior.AllowGet);
}

Vishal JoshiRank #377 · 6.7K reputationPosted Oct 31, 2023, 2:39 AM EDT
Hello,
Please try the below code to get the daily sales amount on the Dashboard.
public JsonResult GetDashboardData() { ASPNETMASTERPOSTEntities db = new ASPNETMASTERPOSTEntities(); var currentDate = DateTime.Now.Date.ToString("dd-MMM-yyyy"); var dailyRevenue = db.tblSales.Where(a => a.OrderDate == currentDate).Sum(b=>b.TotalAmount); return Json(new { dailyRevenue = dailyRevenue }, JsonRequestBehavior.AllowGet); }Thanks
Vishal Joshi
Lokesh VarmanRank #374 · 6.8K reputationPosted Oct 30, 2023, 10:07 AM EDT
do modify the code as per your need
public JsonResult GetDashboardData() { ASPNETMASTERPOSTEntities db = new ASPNETMASTERPOSTEntities(); // Get the current date var currentDate = DateTime.Now.Date; // Query the database to get the sales data for the current date var salesData = db.YourSalesTable .Where(s => s.SaleDate.Date == currentDate) .Select(s => new { Date = s.SaleDate, Amount = s.SaleAmount }) .ToList(); // Return the data as JSON return Json(salesData, JsonRequestBehavior.AllowGet); }Emmmanuel FIADUFERank #947 · 2.2K reputationPosted Oct 30, 2023, 5:35 PM EDT
Thank you Lokesh, I did as you said but is not working
Jignesh KumarRank #91 · 22.9K reputationPosted Oct 31, 2023, 3:05 AM EDT
Hello,
You can use below query to achieve this one,
public JsonResult GetDashboardData() { ASPNETMASTERPOSTEntities db = new ASPNETMASTERPOSTEntities(); DateTime startDateTime = DateTime.Today; //Today at 00:00:00 DateTime endDateTime = DateTime.Today.AddDays(1).AddTicks(-1); //Today at 23:59:59 var dailyRevenue = db.tblSales.Where(a => a.OrderDate >= startDateTime && a.OrderDate b.TotalAmount); return Json(new { dailyRevenue = dailyRevenue }, JsonRequestBehavior.AllowGet); }Emmmanuel FIADUFERank #947 · 2.2K reputationPosted Oct 31, 2023, 7:56 AM EDT
Thank you team, is working now