|
|
|
@ -7,16 +7,21 @@ using Microsoft.EntityFrameworkCore;
|
|
|
|
|
using isnd.Data;
|
|
|
|
|
using isnd.ViewModels;
|
|
|
|
|
using isnd.Helpers;
|
|
|
|
|
using isnd.Interfaces;
|
|
|
|
|
|
|
|
|
|
namespace isnd
|
|
|
|
|
{
|
|
|
|
|
[AllowAnonymous]
|
|
|
|
|
public class PackageVersionController : Controller
|
|
|
|
|
{
|
|
|
|
|
private readonly ApplicationDbContext _context;
|
|
|
|
|
private readonly IPackageManager _pm;
|
|
|
|
|
|
|
|
|
|
public PackageVersionController(ApplicationDbContext context)
|
|
|
|
|
public PackageVersionController(ApplicationDbContext context,
|
|
|
|
|
IPackageManager pm)
|
|
|
|
|
{
|
|
|
|
|
_context = context;
|
|
|
|
|
_pm = pm;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// GET: PackageVersion
|
|
|
|
@ -63,40 +68,39 @@ namespace isnd
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Authorize]
|
|
|
|
|
public async Task<IActionResult> Delete(string pkgid, string version)
|
|
|
|
|
public async Task<IActionResult> Delete(string pkgid, string version, string pkgtype)
|
|
|
|
|
{
|
|
|
|
|
if (pkgid == null || version == null)
|
|
|
|
|
{
|
|
|
|
|
return NotFound();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var packageVersion = await _context.PackageVersions
|
|
|
|
|
.Include(p => p.Package)
|
|
|
|
|
.FirstOrDefaultAsync(m => m.PackageId == pkgid && m.FullString == version);
|
|
|
|
|
if (packageVersion == null)
|
|
|
|
|
{
|
|
|
|
|
return NotFound();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var packageVersion = await _context.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();
|
|
|
|
|
|
|
|
|
|
return View(packageVersion);
|
|
|
|
|
var pkg = await _pm.GetPackageAsync(pkgid, version, pkgtype);
|
|
|
|
|
return View(pkg);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// POST: PackageVersion/Delete/5
|
|
|
|
|
[HttpPost, ActionName("Delete")]
|
|
|
|
|
[ValidateAntiForgeryToken]
|
|
|
|
|
public async Task<IActionResult> DeleteConfirmed(string PackageId, string FullString)
|
|
|
|
|
public async Task<IActionResult> DeleteConfirmed(string PackageId, string FullString,
|
|
|
|
|
string Type)
|
|
|
|
|
{
|
|
|
|
|
var packageVersion = await _context.PackageVersions.Include(p => p.Package)
|
|
|
|
|
.FirstOrDefaultAsync(m => m.PackageId == PackageId && m.FullString == FullString);
|
|
|
|
|
PackageVersion packageVersion = await _context.PackageVersions.Include(p => p.Package)
|
|
|
|
|
.FirstOrDefaultAsync(m => m.PackageId == PackageId
|
|
|
|
|
&& m.FullString == FullString && m.Type == Type);
|
|
|
|
|
if (packageVersion == null) return NotFound();
|
|
|
|
|
if (!User.IsOwner(packageVersion)) return Unauthorized();
|
|
|
|
|
|
|
|
|
|
_context.PackageVersions.Remove(packageVersion);
|
|
|
|
|
await _context.SaveChangesAsync();
|
|
|
|
|
await _pm.DeletePackageAsync(PackageId, FullString, Type);
|
|
|
|
|
return RedirectToAction(nameof(Index));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|