2014-01-31 34 views
1

我有一个方法iv'e连接到我的MVC NopCommerce应用程序中的按钮。我只需要在调试器中获得结果,不需要在视图中显示结果。此方法位于OrderServiceReport类中。没有超载的方法需要0个参数,我错过了什么?

该promlem是,我得到:“方法没有重载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

+0

这建立在通过他们?签名中有“可空”引用类型。 –

+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) 
3

没有重载方法接受0参数,我失去了什么?

参数,如错误解释。

无需默认值(= 42)的参数需要提供一个值,在可为空的值类型或引用类型的情况下,该值可能为null

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

从接口方面,它看起来像至少前五期待值:

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

但我不知道你还可以使用客户端接受这个或那个它需要所有参数是组。

您可能还想考虑使用数据约定而不是这么多的参数。

相关问题