I am trying to display data from database using mvc razor, but I am unable to do so. Here is my code

I am trying to display the total price, group by twine id. but nothing shows up. what could be the possible reason?

view

@model CustomerRevenueModel

@using Nop.Web.Models.Customer

<div class="tab-body revenue">


    @foreach (var revenue in Model.DesignWiseSplits)
    {
        <ul class="info">
            <li> Twine:<span class="order-status ">@revenue.Twine</span></li>
            <li>Designer Share:<span class="order-date">@revenue.DesignerShare.ToString()</span></li>
            <li>Total:<span class="order-total">@revenue.Total</span></li>
        </ul>
    }

Controller

 model.CustomerRevenueModel = PrepareCustomerRevenueModel();

[NonAction]
    protected virtual CustomerRevenueModel PrepareCustomerRevenueModel() 
    {
        var model = new CustomerRevenueModel();
        model.DesignWiseSplits = _orderService.DesignWiseSplits(_workContext.CurrentCustomer.Id);
        return model;
    }

Model

namespace Nop.Web.Models.Customer
{
public partial class CustomerRevenueModel : BaseNopModel
{
    public IList<DesignWiseTotal> DesignWiseSplits { get; set; }
    public IList<Nop.Web.Models.Order.OrderDetailsModel.OrderItemModel> AllDesignerOrderItems { get; set; }
    public int TotalRevenue { get; set; }

}
}

namespace Nop.Services.Orders
{
public class DesignWiseTotal
{
    public decimal Total { get; set; }

    public decimal DesignerShare { get; set; }

    public Twine Twine { get; set; }
}
}

Services

public virtual IList<DesignWiseTotal> DesignWiseSplits(int customerId)
    {
        var query = _orderItemRepository.Table;

        return query.Where(oi => oi.Product.Designer_Id == customerId)
                        .GroupBy(oi => oi.Product.Twine)
                        .Select(oi => new DesignWiseTotal
                        {
                            Total = oi.Sum(x => x.PriceExclTax),
                            Twine = oi.Key
                        }).ToList();
    }

Related posts

Recent Viewed