92 lines
3.0 KiB
C#
92 lines
3.0 KiB
C#
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
using isn.abst;
|
|
using isnd.Data;
|
|
using isnd.Data.Catalog;
|
|
using isnd.Helpers;
|
|
using isnd.ViewModels;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
namespace isnd.Controllers
|
|
{
|
|
|
|
public partial class PackagesController
|
|
{
|
|
// Web search
|
|
public async Task<IActionResult> Index(PackageRegistrationQuery model)
|
|
{
|
|
var pkgs = await packageManager.SearchPackageAsync(model);
|
|
|
|
return View(new RegistrationPageIndexQueryAndResult
|
|
{
|
|
Query = model,
|
|
Result = pkgs.ToArray()
|
|
});
|
|
}
|
|
|
|
public async Task<IActionResult> Details(PackageDetailViewModel model)
|
|
{
|
|
if (model.pkgid == null)
|
|
{
|
|
return NotFound();
|
|
}
|
|
|
|
var packageVersion = dbContext.PackageVersions
|
|
.Include(p=>p.LatestCommit)
|
|
.Include(p => p.Package)
|
|
.Where(m => m.PackageId == model.pkgid)
|
|
.OrderByDescending(p => p)
|
|
;
|
|
|
|
if (packageVersion.Count() == 0)
|
|
{
|
|
return NotFound();
|
|
}
|
|
bool results = await packageVersion.AnyAsync();
|
|
model.latest = await packageVersion.FirstAsync();
|
|
model.totalHits = packageVersion.Count();
|
|
model.data = packageVersion.Take(MAX_PKG_VERSION_LIST).ToArray();
|
|
|
|
return View("Details", model);
|
|
}
|
|
const int MAX_PKG_VERSION_LIST = 50;
|
|
|
|
[Authorize, HttpGet]
|
|
public async Task<IActionResult> Delete(string pkgid, string version, string pkgtype)
|
|
{
|
|
if (pkgid == null || version == null)
|
|
{
|
|
return NotFound();
|
|
}
|
|
|
|
var packageVersion = await dbContext.PackageVersions.Include(p => p.Package)
|
|
.FirstOrDefaultAsync(m => m.PackageId == pkgid
|
|
&& m.FullString == version && m.Type == pkgtype);
|
|
if (packageVersion == null) return NotFound();
|
|
if (!User.IsOwner(packageVersion)) return Unauthorized();
|
|
var pkg = await packageManager.GetPackageAsync(pkgid, version, pkgtype);
|
|
return View(pkg);
|
|
}
|
|
|
|
// POST: PackageVersion/Delete/5
|
|
[HttpPost]
|
|
[ValidateAntiForgeryToken]
|
|
public async Task<IActionResult> DeleteConfirmed(string PackageId, string FullString,
|
|
string Type)
|
|
{
|
|
PackageVersion packageVersion = await dbContext.PackageVersions
|
|
.Include(pv => pv.Package)
|
|
.FirstOrDefaultAsync(m => m.PackageId == PackageId
|
|
&& m.FullString == FullString && m.Type == Type);
|
|
if (packageVersion == null) return NotFound();
|
|
if (!User.IsOwner(packageVersion)) return Unauthorized();
|
|
|
|
await packageManager.DeletePackageAsync(PackageId, FullString, Type);
|
|
return RedirectToAction(nameof(Index));
|
|
}
|
|
}
|
|
|
|
} |