2021-05-22 22:49:57 +01:00
|
|
|
using System.Linq;
|
|
|
|
|
using System.Security.Claims;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using Microsoft.AspNetCore.Authorization;
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
2021-08-15 19:09:01 +01:00
|
|
|
using isnd.Data;
|
|
|
|
|
using isnd.ViewModels;
|
2021-09-05 15:44:47 +01:00
|
|
|
using isnd.Helpers;
|
2021-09-05 17:10:50 +01:00
|
|
|
using isnd.Interfaces;
|
|
|
|
|
|
2021-08-15 19:09:01 +01:00
|
|
|
namespace isnd
|
2021-05-22 22:49:57 +01:00
|
|
|
{
|
|
|
|
|
[AllowAnonymous]
|
|
|
|
|
public class PackageVersionController : Controller
|
|
|
|
|
{
|
|
|
|
|
private readonly ApplicationDbContext _context;
|
2021-09-05 17:10:50 +01:00
|
|
|
private readonly IPackageManager _pm;
|
2021-05-22 22:49:57 +01:00
|
|
|
|
2021-09-05 17:10:50 +01:00
|
|
|
public PackageVersionController(ApplicationDbContext context,
|
|
|
|
|
IPackageManager pm)
|
2021-05-22 22:49:57 +01:00
|
|
|
{
|
|
|
|
|
_context = context;
|
2021-09-05 17:10:50 +01:00
|
|
|
_pm = pm;
|
2021-05-22 22:49:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// GET: PackageVersion
|
|
|
|
|
public async Task<IActionResult> Index(PackageVersionIndexViewModel model)
|
|
|
|
|
{
|
2021-08-11 23:25:15 +01:00
|
|
|
var applicationDbContext = _context.PackageVersions.Include(p => p.Package).Where(
|
2021-09-05 17:10:50 +01:00
|
|
|
p => (model.Prerelease || !p.IsPrerelease)
|
2021-08-11 23:25:15 +01:00
|
|
|
&& ((model.PackageId == null) || p.PackageId.StartsWith(model.PackageId)));
|
2021-08-11 20:45:40 +01:00
|
|
|
model.Versions = await applicationDbContext.ToArrayAsync();
|
2021-05-22 22:49:57 +01:00
|
|
|
return View(model);
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-05 21:24:37 +01:00
|
|
|
[Authorize]
|
|
|
|
|
public async Task<IActionResult> Mines(PackageVersionIndexViewModel model)
|
|
|
|
|
{
|
|
|
|
|
var userId = User.FindFirstValue(ClaimTypes.NameIdentifier);
|
|
|
|
|
var applicationDbContext = _context.PackageVersions
|
|
|
|
|
.Include(p => p.Package).Where(
|
|
|
|
|
p => (string.IsNullOrEmpty(model.PackageId) || p.PackageId.StartsWith(model.PackageId))
|
|
|
|
|
&& p.Package.OwnerId == userId);
|
|
|
|
|
|
2021-08-11 20:45:40 +01:00
|
|
|
model.Versions = await applicationDbContext.ToArrayAsync();
|
2021-07-05 21:24:37 +01:00
|
|
|
|
|
|
|
|
return View("Index", model);
|
|
|
|
|
}
|
2021-05-22 22:49:57 +01:00
|
|
|
}
|
|
|
|
|
}
|