没有方法的重载需要0个参数,我缺少什么?

时间:2014-01-31 13:04:29

标签: c# asp.net-mvc entity-framework nopcommerce

我有一个方法iv连接到我的MVC NopCommerce应用程序中的按钮。我只需要在调试器中得到结果,不需要在视图中显示结果。此方法位于OrderServiceReport类中。

这个问题是我得到的:"方法没有重载需要0个参数"当我在控制器类中调用我的方法时。我想我需要在这里添加参数吗?

这是我的代码..

IOrderReportService:

IList<BestsellersReportLine> DailyBestsellersReport(DateTime? startTime,
    DateTime? endTime, OrderStatus? os, PaymentStatus? ps, ShippingStatus? ss,
    int billingCountryId = 0,
    int recordsToReturn = 5, int orderBy = 1, int groupBy = 1, bool showHidden = false);

OrderReportService类:

public IList<BestsellersReportLine> DailyBestsellersReport(DateTime? startTime,
        DateTime? endTime, OrderStatus? os, PaymentStatus? ps, ShippingStatus? ss,
        int billingCountryId = 0,
        int recordsToReturn = 5, int orderBy = 1, int groupBy = 1, bool showHidden = false)
    {



        int? orderStatusId = null;
        if (os.HasValue)
            orderStatusId = (int)os.Value;

        int? paymentStatusId = null;
        if (ps.HasValue)
            paymentStatusId = (int)ps.Value;

        int? shippingStatusId = null;
        if (ss.HasValue)
            shippingStatusId = (int)ss.Value;


        var query1 = from opv in _opvRepository.Table
                     join o in _orderRepository.Table on opv.OrderId equals o.Id
                     join pv in _productVariantRepository.Table on opv.ProductVariantId equals pv.Id
                     join p in _productRepository.Table on pv.ProductId equals p.Id
                     where (!startTime.HasValue || startTime.Value <= o.CreatedOnUtc) &&
                     (!endTime.HasValue || endTime.Value >= o.CreatedOnUtc) &&
                     (!orderStatusId.HasValue || orderStatusId == o.OrderStatusId) &&
                     (!paymentStatusId.HasValue || paymentStatusId == o.PaymentStatusId) &&
                     (!shippingStatusId.HasValue || shippingStatusId == o.ShippingStatusId) &&
                     (!o.Deleted) &&
                     (!p.Deleted) &&
                     (!pv.Deleted) &&
                     (billingCountryId == 0 || o.BillingAddress.CountryId == billingCountryId) &&
                     (showHidden || p.Published) &&
                     (showHidden || pv.Published)
                     select opv;


        var query2 = groupBy == 1 ?
            //group by product variants
               from opv in query1
               group opv by opv.ProductVariantId into g
               select new
               {
                   EntityId = g.Key,
                   TotalAmount = g.Sum(x => x.PriceExclTax),
                   TotalQuantity = g.Sum(x => x.Quantity),
               }
               :
            //group by products
               from opv in query1
               group opv by opv.ProductVariant.ProductId into g
               select new
               {
                   EntityId = g.Key,
                   TotalAmount = g.Sum(x => x.PriceExclTax),
                   TotalQuantity = g.Sum(x => x.Quantity),
               }
               ;

        switch (orderBy)
        {
            case 1:
                {
                    query2 = query2.OrderByDescending(x => x.TotalQuantity);
                }
                break;
            case 2:
                {
                    query2 = query2.OrderByDescending(x => x.TotalAmount);
                }
                break;
            default:
                throw new ArgumentException("Wrong orderBy parameter", "orderBy");
        }

        if (recordsToReturn != 0 && recordsToReturn != int.MaxValue)
            query2 = query2.Take(recordsToReturn);

        var result = query2.ToList().Select(x =>
        {
            var reportLine = new BestsellersReportLine()
            {
                EntityId = x.EntityId,
                TotalAmount = x.TotalAmount,
                TotalQuantity = x.TotalQuantity
            };
            return reportLine;
        }).ToList();



        return result;

    }

OrderController类:

public ActionResult SendDailyReport()
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageCatalog))
                return AccessDeniedView();

            try
            {
                _orderReportService.DailyBestsellersReport();


            }
            catch (Exception ex)
            { }
            return RedirectToAction("List");
        }

查看:

<a href="@Url.Action("SendDailyReport")" class="t-button">@T("Admin.Common.DailyBestsellersSend.All")</a>

出了什么问题?

THX

2 个答案:

答案 0 :(得分:3)

  

方法没有重载需要0个参数,我缺少什么?

参数,如错误解释。

不需要默认值(= 42)的参数需要提供一个值,如果值为可空值类型或引用类型,则可能为null

如果您查看生成的WCF客户端代理代码(或者您调用此服务),您可以查看它所期望的参数以及可用的重载(如果有)。

从界面看,至少前五个看起来是一个值:

_orderReportService.DailyBestsellersReport(null, null, null, null, null);

但我不确定您使用的客户端是否也接受此要求或者要求设置所有参数。

您可能还想考虑使用数据协定而不是那么多参数。

答案 1 :(得分:1)

您有没有默认值的参数。

在调用方法时,它们可以为空的事实并没有改变你需要为这些参数添加内容的事实。

如果您希望能够在不添加参数的情况下调用方法,请使用

IList<BestsellersReportLine> DailyBestsellersReport(DateTime? startTime = null,
    DateTime? endTime = null, OrderStatus? os = null, PaymentStatus? ps = null, ShippingStatus? ss = null,
    int billingCountryId = 0,
    int recordsToReturn = 5, int orderBy = 1, int groupBy = 1, bool showHidden = false);

如果您还需要传递这些参数,请在调用方法时传递它们

xxx.DailyBestsellerReport(null, null, null, null, null)