I don`t know how to display, at the beginning the sum of the orders of the month in the table in the asp.net MVC. My data in table Order look like:
DateCreated | TotalPrice
2017-02-06 | 400
2017-02-06 | 300
2017-03-06 | 100
2017-03-06 | 50
And I want to get mountly sum of TotalPrice, like this:
DateCreated | TotalPrice
2017-02 | 700
2017-03 | 150
My model class Order:
public int orderId { get; set; }
public string UserId { get; set; }
public virtual ApplicationUser User { get; set; }
[StringLength(100)]
public string firstName { get; set; }
[StringLength(150)]
public string lastName { get; set; }
[StringLength(150)]
public string address { get; set; }
[StringLength(20)]
public string phoneNumber { get; set; }
public string email { get; set; }
public string comment { get; set; }
public DateTime dateCreated { get; set; }
public OrderState orderState { get; set; }
public decimal totalPrice { get; set; }
public List<OrderIteam> OrderIteams { get; set; }
I try to write something like this to display the sum of the orders of the month in the table :
public ActionResult ListOrder()
{
var result =
from s in db.Orders
group s by new { date = new DateTime(s.dateCreated.Year, s.dateCreated.Month, 1) } into g
select new
{
dateCreated = g.Key.date,
sumTotalPrice = g.Sum(x => x.totalPrice)
};
return View(result);
}
I am getting the error message:
The model item passed into the dictionary is of type 'System.Data.Entity.Infrastructure.DbQuery
1[<>f__AnonymousType5
2[System.DateTime,System.Decimal]]', but this dictionary requires a model item of type 'System.Collections.Generic.IEnumerable`1[Sklep_Internetowy.Models.Order]'.
At the end I would like to show that the sum of the orders of a given month as the chart below: Chart