public async Task <IPagedList <Dto.User> > GetUsersAsync(UserSearchContext search = null) { var filter = new List <Expression <Func <V_User, bool> > >(); //Parse filters if (search != null) { if (!string.IsNullOrEmpty(search.Badge)) { filter.Add(u => u.Badge.Contains(search.Badge.Trim())); } if (search.Active.HasValue) { filter.Add(u => u.UserActive == search.Active.Value); } if (string.IsNullOrWhiteSpace(search.SortField)) { search.SortField = "Badge"; } } else { search = new UserSearchContext { SortField = "Badge" } }; //Build expression tree var whereClause = filter.Aggregate((Expression <Func <V_User, bool> >)null, (current, f) => current == null ? f : current.And(f)); var query = UnitOfWork.Get <V_User>(); if (whereClause != null) { query = query.Where(whereClause); } var users = await query .DynamicOrderBy(search.SortField, (OrderByDirection)Enum.Parse(typeof(OrderByDirection), search.SortDirection.ToString())) .ToPagedListAsync(search.PageNumber, search.PageSize); return(users.Select(Converter.ToModel)); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env, UserSearchContext userSearchContext) { if (env.IsDevelopment()) { app.UseBrowserLink(); app.UseDeveloperExceptionPage(); } else { app.UseExceptionHandler("/Home/Error"); } app.UseStaticFiles(); app.UseMvc(routes => { routes.MapRoute( name: "default", template: "{controller=Home}/{action=Index}/{id?}"); }); SeedData.Initialize(userSearchContext); //userSearchContext.Database.EnsureCreated(); }
public HomeController(UserSearchContext userSearchContext) { UserSearchContext = userSearchContext ?? throw new ArgumentNullException(nameof(userSearchContext)); }
public UsersController(UserSearchContext context) { _context = context; }