2014-01-31 38 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); 

但我不知道你還可以使用客戶端接受這個或那個它需要所有參數是組。

您可能還想考慮使用數據約定而不是這麼多的參數。

相關問題