public List <Fruitdev> GetDataFromDbase(WebApplication2Context _context, string searchBy, int take, int skip, string sortBy, bool sortDir, out int filteredResultsCount, out int totalResultsCount) { // the example datatable used is not supporting multi column ordering // so we only need get the column order from the first column passed to us. var whereClause = BuildDynamicWhereClause(_context, searchBy); if (String.IsNullOrEmpty(searchBy) && false) { // if we have an empty search then just order the results by Id ascending sortBy = "id"; sortDir = true; } var result = _context.Getsp(1) .AsExpandable() .Where(whereClause) .Select(m => new Fruitdev { id = m.id, Nome = m.Nome, dev = m.dev }) .OrderByAD(sortBy, sortDir) // have to give a default order when skipping .. so use the PK .Skip(skip) .Take(take) .ToList(); // now just get the count of items (without the skip and take) - eg how many could be returned with filtering filteredResultsCount = _context.Getsp(1).ToList().AsQueryable().AsExpandable().Where(whereClause).Count(); totalResultsCount = _context.Getsp(1).ToList().AsQueryable().Count(); return(result); }
public IList <Fruitdev> YourCustomSearchFunc(WebApplication2Context _context, DataTableAjaxPostModel model, out int filteredResultsCount, out int totalResultsCount) { var searchBy = (model.search != null) ? model.search.value : null; var take = model.length; var skip = model.start; string sortBy = ""; bool sortDir = true; if (model.order != null) { // in this example we just default sort on the 1st column sortBy = model.columns[model.order[0].column].data; sortDir = model.order[0].dir.ToLower() == "asc"; } // search the dbase taking into consideration table sorting and paging var result = GetDataFromDbase(_context, searchBy, take, skip, sortBy, sortDir, out filteredResultsCount, out totalResultsCount); if (result == null) { // empty collection... return(new List <Fruitdev>()); } return(result); }
private Expression <Func <Fruitdev, bool> > BuildDynamicWhereClause(WebApplication2Context entities, string searchValue) { // simple method to dynamically plugin a where clause var predicate = PredicateBuilder.New <Fruitdev>(true); // true -where(true) return all if (String.IsNullOrWhiteSpace(searchValue) == false) { // as we only have 2 cols allow the user type in name 'firstname lastname' then use the list to search the first and last name of dbase var searchTerms = searchValue.Split(' ').ToList().ConvertAll(x => x.ToLower()); predicate = predicate.Or(s => s.id.ToString().ToLower().Contains(searchValue)); predicate = predicate.Or(s => s.Nome.ToLower().Contains(searchValue));//searchValue.Any(srch => s.Nome.ToLower().Contains(srch))); } return(predicate); }
public static void Initialize(IServiceProvider serviceProvider) { using (var context = new WebApplication2Context(serviceProvider.GetRequiredService <DbContextOptions <WebApplication2Context> >())) { if (context.Movie.Any()) { return; } context.Movie.AddRange( new Movie { Title = "When Harry Met Sally", ReleaseDate = DateTime.Parse("1989-2-12"), Genre = "Romantic Comedy", Price = 7.99M, Rating = "R" }, new Movie { Title = "Ghostbusters ", ReleaseDate = DateTime.Parse("1984-3-13"), Genre = "Comedy", Price = 8.99M, Rating = "R" }, new Movie { Title = "Ghostbusters 2", ReleaseDate = DateTime.Parse("1986-2-23"), Genre = "Comedy", Price = 9.99M, Rating = "R" }, new Movie { Title = "Rio Bravo", ReleaseDate = DateTime.Parse("1959-4-15"), Genre = "Western", Price = 3.99M, Rating = "R" } ); context.SaveChanges(); } }
public static void Initialize(IServiceProvider serviceProvider) { { using (var context = new WebApplication2Context(serviceProvider.GetRequiredService <DbContextOptions <WebApplication2Context> >())) { //Look for any movies if (context.Game.Any()) { return; //DB has been seeded } context.Game.AddRange( new Game { tytul = "CS:GO", data_wydania = DateTime.Parse("01-11-2008"), gatunek = "Akcji/Multiplayer", ocena = "18+", cena = 2 }, new Game { tytul = "Battlefield", data_wydania = DateTime.Parse("01-11-2010"), gatunek = "Akcji/Multiplayer", ocena = "18+", cena = 2 }, new Game { tytul = "Skyrim", data_wydania = DateTime.Parse("01-11-2012"), gatunek = "Akcji/RPG", ocena = "13+", cena = 2 } ); context.SaveChanges(); } } }
public EditModel(WebApplication2.Models.WebApplication2Context context) { _context = context; }
public DetailsModel(WebApplication2.Models.WebApplication2Context context) { _context = context; }
public DeleteModel(WebApplication2.Models.WebApplication2Context context) { _context = context; }
public IndexModel(WebApplication2.Models.WebApplication2Context context) { _context = context; }
//2. as is this public IndexModel(WebApplication2.Models.WebApplication2Context context) { _context = context; // Why couldn't I have renamed this _db so it stands for database. }