Hello Team I want to count item quantity and critical stock from my mvc controller and pass to dashboard, kindly assist.
public JsonResult GetDashboardData()
{
ASPNETMASTERPOSTEntities db = new ASPNETMASTERPOSTEntities();
var currentDate = DateTime.Now.Date.ToString("dd-MMM-yyyy");
return Json(JsonRequestBehavior.AllowGet);
}
Vishal JoshiPosted Oct 31, 2023, 6:35 AM
Hello Emmanuel,
You can try the below code. you need to sum up the quantity to get the item quantity count and get the critical stock needed group by stock item and sum up. if the total is less than the critical count consider it as critical stock count.
Vishal Joshi
Thanks
Aravind GovindarajPosted Oct 31, 2023, 1:18 PM
Hi Emmanuel. Typically I would like to say this is aggregated data, so instead of computing from a transaction table. I suggest creating another data product which supposed to act as aggregated data that you are planning to display in the dashboard.
Thanks
Aravind Govindaraj
Emmmanuel FIADUFEPosted Oct 31, 2023, 11:57 AM
Thank you team,
Everything is working now.
Prasad RaveendranPosted Oct 31, 2023, 3:41 AM
try something like this
Replace the entity names and fields (
Items,Quantity,Stock,CriticalThreshold, etc.) with the appropriate names from your database.Once you've retrieved the required data (total quantity and critical stock count), you create an instance of a class (
DashboardData) with the retrieved values and return it as JSON in the response.Make sure to handle errors or exceptions appropriately and ensure that your Entity Framework model matches your database schema for this code to work correctly.
Finally, in your frontend code (JavaScript or whatever you're using), you can fetch this JSON data from your MVC Controller and render it on your dashboard as needed.