/// <summary> /// 處理在Index ViewModel所需要做的事情 /// </summary> /// <typeparam name="TSearchForm">搜索form的形態</typeparam> /// <typeparam name="TPageResult">搜索結果的形態</typeparam> /// <param name="searchViewModel">搜索相關的viewmodel</param> /// <param name="wherePredicate">當不用預設的where處理邏輯的時候,傳入的自訂where條件</param> /// <param name="includes">需要Include進來的其他Entity</param> public virtual void ProcessIndexViewModel <TSearchForm, TPageResult>(Common.Base.ISearchViewModelBase <TSearchForm, TPageResult> searchViewModel, System.Linq.Expressions.Expression <Func <T, bool> > wherePredicate = null, params System.Linq.Expressions.Expression <Func <T, object> >[] includes) where TSearchForm : Common.Base.ISearchFormViewModelBase, new() { var data = db.Repository <T>().Reads(); foreach (var item in includes) { data.Include(item); } // 如果沒有where條件,表示依照預設邏輯 if (wherePredicate == null) { // 當沒有給filter條件並且搜索條件屬於前台看的 if (searchViewModel.SearchForm is IFrontViewModel) { SearchViewModelProcess.ApplySearchFormForFront <T, TSearchForm, TPageResult>(data, searchViewModel); } else { SearchViewModelProcess.ApplySearchForm <T, TSearchForm, TPageResult>(data, searchViewModel); } } else { SearchViewModelProcess.ApplySearchForm <T, TSearchForm, TPageResult>(data, searchViewModel, wherePredicate); } }
/// <summary> /// 用IndexViewModel產生出要匯出的內容 /// </summary> /// <typeparam name="TSearchForm">搜索form的形態</typeparam> /// <typeparam name="TPageResult">搜索結果的形態</typeparam> /// <param name="searchViewModel">搜索相關的viewmodel</param> /// <param name="wherePredicate">傳入要匯出的資料條件</param> /// <param name="includes">需要Include進來的其他Entity</param> public virtual void ProcessExportViewModel <TSearchForm, TPageResult>(Common.Base.ISearchViewModelBase <TSearchForm, TPageResult> searchViewModel, System.Linq.Expressions.Expression <Func <T, bool> > wherePredicate = null, params System.Linq.Expressions.Expression <Func <T, object> >[] includes) where TSearchForm : Common.Base.ISearchFormViewModelBase, new() { var data = db.Repository <T>().Reads(); foreach (var item in includes) { data.Include(item); } SearchViewModelProcess.ApplySearchForm <T, TSearchForm, TPageResult>(data, searchViewModel, wherePredicate); }