2017-09-11 66 views
0

我已經定義了一個在AppService文件中定義的方法,方法的簽名爲public PagedResultDto<FetchData> GetSearchData(FetchDataInput searchInput)。我從Angular代碼中調用此方法,但service-proxoes.ts文件已生成方法,我需要逐個傳遞所有參數。如何在ASP.NET Boilerplate中調用方法中的對象來調用服務API?

public class FetchDataInput: PagedAndSortedInputDto, IShouldNormalize 
{ 
    public int DataLevel { get; set; } 
    public int DataType { get; set; } 
    public string DataCode { get; set; } 
    public string DescLong { get; set; } 
    public string LanguageCode { get; set; } 
    public string DataParent { get; set; } 

    public void Normalize() 
    { 
     if (string.IsNullOrEmpty(Sorting)) 
     { 
      Sorting = "DataCode"; 
     } 
    } 

} 

服務的Proxies.ts文件:

getSearchData(dataLevel: number, dataType: number, dataCode: string, descLong: string, languageCode: string, dataParent: string, sorting: string, maxResultCount: number, skipCount: number): Observable<PagedResultDtoOfFetchData> { 

所以我要呼籲通過以下方式getSearchData方法。所以我必須通過所有的參數,但是如果我們假設有100個參數,那麼它將是容易出錯和編程風格不佳的。所以它必須帶上一個類對象。那麼有沒有辦法做到這一點?

回答

0

您可以創建一個對象來存儲這些parametter這樣的:

public class FetchDataInput: PagedAndSortedInputDto, IShouldNormalize 
{ 
    public SearchModel searchModel{get; set;} 

    public void Normalize() 
    {   
     if (string.IsNullOrEmpty(Sorting)) 
     { 
      Sorting = "DataCode"; 
     } 
    } 

} 

public class SearchModel 
{ 
     public int DataLevel { get; set; } 
     public int DataType { get; set; } 
     public string DataCode { get; set; } 
     public string DescLong { get; set; } 
     public string LanguageCode { get; set; } 
     public string DataParent { get; set; } 
} 

...而在getSearchData,試圖序列模型並將其傳遞給您的API:

_$SearchModelForm= _modalManager.getModal().find('form[name=SearchForm]'); 
var searchModel = _$SearchModelForm.serializeFormToObject(); 
this._dataService.getSearchData(searchModel);