Prvi commit
This commit is contained in:
48
EveryThing/Pages/AdministrationCompanies/Index.cshtml.cs
Normal file
48
EveryThing/Pages/AdministrationCompanies/Index.cshtml.cs
Normal file
@@ -0,0 +1,48 @@
|
||||
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<CodeTableCompany> 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user