I have three kind of products showing on my index view divided in 3 slots like this
<div class="panel panel-body">
<div class="col-md-4 table-responsive" id="carTable"></div>
<div class="col-md-4 table-responsive" id="boatTable"></div>
<div class="col-md-4 table-responsive" id="otherProductsTable"></div>
</div>
and working great. Departments like Ny, Dubai .. are dynamic and this is my class:
public class Departments
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int DeptId { get; set; }
public string DeptName { get; set; }
}
But now I am trying to show a summary of my products including department they belong to, like this screenshot below shows:
By coding like this:
public async Task<ActionResult> GetProductSummary()
{
using (context)
{
return (PartialView("_ProductSummary", await context.Inventories.Include(b =>b.KindOfProducts).GroupBy(m => m.KindOfProducts.ProductType).Select(g => new InventoryModel { BetName = g.Key, Status = g.Sum(c => c.Status) }).ToListAsync()));
}
}
I got a result like this shown in this screenshot:
But what I really want is like this:
I do not know How to change my Linq query and before that how to create a good structured ViewModel. Right now I have this incomplete ViewModel:
public class InventoryModel
{
// I don't know if I need all this properties...
public KindOfProducts ProductType { get; set; }
public string ProductType { get; set; }
public int KindOfProductId { get; set; }
public Department department { get; set; }
public string DeptName { get; set; }
public int DeptId { get; set; }
public int Status { get; set; }
}
Thank you in advance!