+ Pred kreiranjem povpraševanja vprašaj za partnerja + Prikaz TOP 100 (predolgo nalaga) + Dodaj Sorovec na Urejanje Artikla (zadnji surovec) + V Urejanju artikla popravi opis v pot dokumentov + Kooperant
81 lines
3.0 KiB
C#
81 lines
3.0 KiB
C#
using EveryThing.Data;
|
|
using EveryThing.Models;
|
|
using EveryThing.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 EveryThing.Pages.CodeTablePartners
|
|
{
|
|
[Authorize(Roles = "Administrator,InvoicingUser,ProjecThingUser,TransportThingUser")]
|
|
public class IndexModel : PageModel
|
|
{
|
|
private readonly EveryThing.Data.ApplicationDbContext _context;
|
|
private readonly UserManager<IdentityApplicationUser> _userManager;
|
|
|
|
public IndexModel(EveryThing.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 });
|
|
}
|
|
}
|
|
}
|