using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.RazorPages; using Microsoft.EntityFrameworkCore; using EveryThing.Data; using EveryThing.Models; using Microsoft.AspNetCore.Authorization; using EveryThing.Models.CodeTable; namespace EveryThing.Pages.AdministrationCompanies { [Authorize(Roles = "Administrator")] public class IndexModel : PageModel { private readonly ApplicationDbContext _context; public IndexModel(ApplicationDbContext context) { _context = context; } public IList Company { get;set; } public async Task OnGetAsync(string searchString, string inactiveCompanies) { ViewData["SearchString"] = searchString; ViewData["InactiveCompanies"] = inactiveCompanies == "on" ? "checked" : ""; Company = await _context.CodeTableCompanies .Include(c => c.Country).ToListAsync(); // Active companies if (string.IsNullOrEmpty(inactiveCompanies) || inactiveCompanies != "on") { Company = Company.Where(s => s.Active).ToList(); } // Search string if (!string.IsNullOrEmpty(searchString)) { Company = Company.Where(s => s.ShortTitle.Contains(searchString) || s.Title.Contains(searchString)).ToList(); } } } }