Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class SomeForm : Form, ISomeFormView
- {
- public OnAction()
- {
- Presenter.DoSearch();
- }
- public SearchModel GetModelForSearch()
- {
- var model = new SearchModel
- {
- SearchText1 = txtTextBox1.Text,
- IsSuperSearch = rbIsSuper.Value,
- ...
- };
- }
- //...
- }
- class SomeFormPresenter
- {
- //...
- public class DoSearch()
- {
- var model = view.GetModelForSearch();
- var query = IoC.Resolve<SearchQuery>();
- var result = query.Execute(model);
- view.ShowResult(result);
- }
- }
- class SearchQuery
- {
- private readonly IDataContext dataContext;
- public SearchQuery(IDataContext dataContext)
- {
- this.dataContext = dataContext;
- }
- public IEnumerable<Result> Execute(SearchModel model)
- {
- IQueryable<Result> query = null;
- //...
- if (string.IsNullOrEmpty(model.SearchText1) == false)
- {
- query = query.Where(x=>x.Text == model.SearchText1);
- }
- // дальше наращиваем query в зависимости от условий
- // это обычный вызов лямбда выражения, который производит выборку из БД. В твоем случае IDataContext будет реализовывать EF
- return dataContext.Query(query);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement