I need to calculate how many orders there are in total every day and print them in the datatable day by day. I have to perform this time allocation based on the OrderDate value in my table. I need to find the total number of orders for each day.
I want to do:
| Date | Total Order |
|---|---|
| 09.10.2022 | 45 |
| 09.11.2022 | 60 |
| 09.12.2022 | 75 |
Order class:
public class Order : IBaseEntity
{
[Key]
public int OrderId { get; set; }
public int UserId { get; set; }
public int RestaurantId { get; set; }
public int AddressId { get; set; }
public int? PromotionId { get; set; }
public DateTime OrderDate { get; set; }
public DateTime? DeliveryDate { get; set; }
public OrderStatues OrderStatus { get; set; }
public bool DropDoor { get; set; }
public bool RingBell { get; set; }
public string OrderNote { get; set; }
public OrderTypes OrderType { get; set; }
public string PaymentType { get; set; }
public decimal SubTotal { get; set; }
public decimal DiscountTotal { get; set; }
public decimal OrderTotal { get; set; }
public decimal DeliveryCost { get; set; }
public OrderSources OrderSource { get; set; }
public OrderTimes OrderTime { get; set; }
public OrderDays OrderDay { get; set; }
[NotMapped]
public int[] SelectedProducts { get; set; }
[NotMapped]
public int OrderHour { get; set; }
public virtual Restaurant Restaurant { get; set; }
public virtual User User { get; set; }
public virtual Address Address { get; set; }
public virtual Promotion Promotion { get; set; }
public virtual ICollection<JoinOrderProduct> JoinOrderProducts { get; set; } = new HashSet<JoinOrderProduct>();
public void Build(ModelBuilder builder)
{
builder.Entity<Order>(entity =>
{
entity
.HasKey(p => new { p.OrderId});
entity
.HasOne(p => p.Restaurant)
.WithMany(p => p.Orders)
.HasForeignKey(p => p.RestaurantId)
.OnDelete(DeleteBehavior.Cascade);
entity
.Property(p => p.SubTotal)
.HasPrecision(18, 4)
.IsRequired();
entity
.Property(p => p.DiscountTotal)
.HasPrecision(18, 4)
.IsRequired();
entity
.Property(p => p.OrderTotal)
.HasPrecision(18, 4)
.IsRequired();
entity
.Property(p => p.DeliveryCost)
.HasPrecision(18, 4)
.IsRequired();
});
}
}