rename to projecting
This commit is contained in:
80
ProjecThing/Pages/CodeTablePartners/Index.cshtml.cs
Normal file
80
ProjecThing/Pages/CodeTablePartners/Index.cshtml.cs
Normal file
@@ -0,0 +1,80 @@
|
||||
using ProjecThing.Data;
|
||||
using ProjecThing.Models;
|
||||
using ProjecThing.Models.CodeTable;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Identity;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||
using Microsoft.Data.SqlClient;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Security.Cryptography.X509Certificates;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjecThing.Pages.CodeTablePartners
|
||||
{
|
||||
[Authorize(Roles = "Administrator,InvoicingUser,ProjecThingUser,TransportThingUser")]
|
||||
public class IndexModel : PageModel
|
||||
{
|
||||
private readonly ProjecThing.Data.ApplicationDbContext _context;
|
||||
private readonly UserManager<IdentityApplicationUser> _userManager;
|
||||
|
||||
public IndexModel(ProjecThing.Data.ApplicationDbContext context, UserManager<IdentityApplicationUser> userManager)
|
||||
{
|
||||
_context = context;
|
||||
_userManager = userManager;
|
||||
}
|
||||
|
||||
public IList<CodeTablePartner> Partner { get;set; }
|
||||
|
||||
public async Task OnGetAsync(string searchString)
|
||||
{
|
||||
ViewData["SearchString"] = searchString;
|
||||
|
||||
var user = _userManager.GetUserAsync(User).Result;
|
||||
|
||||
Partner = await _context.CodeTablePartners
|
||||
.Where(x => x.IdCompanyFk == user.IdCompanyFk)
|
||||
.Include(p => p.Country)
|
||||
.Include(c => c.Company)
|
||||
.OrderBy(x => x.Title).ToListAsync();
|
||||
|
||||
if (!string.IsNullOrEmpty(searchString))
|
||||
{
|
||||
Partner = Partner.Where(x => (x.Title != null && x.Title.Contains(searchString, StringComparison.InvariantCultureIgnoreCase))
|
||||
|| (x.Post != null && x.Post.Contains(searchString, StringComparison.InvariantCultureIgnoreCase))
|
||||
|| (x.Street != null && x.Street.Contains(searchString, StringComparison.InvariantCultureIgnoreCase))
|
||||
|| (x.TaxNumber != null && x.TaxNumber.Contains(searchString, StringComparison.InvariantCultureIgnoreCase)))
|
||||
.ToList();
|
||||
}
|
||||
}
|
||||
|
||||
public IActionResult OnGetPartners(bool? suppliers)
|
||||
{
|
||||
var user = _userManager.GetUserAsync(User).Result;
|
||||
|
||||
var successful = true;
|
||||
var error = "";
|
||||
|
||||
var partners = _context.CodeTablePartners
|
||||
.Where(x => x.IdCompanyFk == user.IdCompanyFk);
|
||||
|
||||
if (suppliers != null)
|
||||
partners = partners.Where(x => x.Supplier == suppliers);
|
||||
|
||||
var sbJson = new StringBuilder();
|
||||
|
||||
foreach (var codeTablePartner in partners)
|
||||
{
|
||||
if (sbJson.Length > 0)
|
||||
sbJson.Append(",");
|
||||
sbJson.Append($"\"{codeTablePartner.IdPartner}\": \"{codeTablePartner.Title}\"");
|
||||
}
|
||||
|
||||
return new JsonResult(new { jsonPartners = $"{{{sbJson}}}", error = error, successful = successful });
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user