gestion des versions :
* dossier des versions = FullString * Suppressioni de versionsbroken/ef
parent
41fbe54638
commit
be30ef3c25
@ -0,0 +1,96 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Security.Claims;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Microsoft.AspNetCore.Authorization;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Microsoft.AspNetCore.Mvc.Rendering;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using nuget_host.Data;
|
||||||
|
using nuget_host.ViewModels;
|
||||||
|
|
||||||
|
namespace nuget_host
|
||||||
|
{
|
||||||
|
[AllowAnonymous]
|
||||||
|
public class PackageVersionController : Controller
|
||||||
|
{
|
||||||
|
private readonly ApplicationDbContext _context;
|
||||||
|
|
||||||
|
public PackageVersionController(ApplicationDbContext context)
|
||||||
|
{
|
||||||
|
_context = context;
|
||||||
|
}
|
||||||
|
|
||||||
|
// GET: PackageVersion
|
||||||
|
public async Task<IActionResult> Index(PackageVersionIndexViewModel model)
|
||||||
|
{
|
||||||
|
var applicationDbContext = _context.PackageVersions.Include(p => p.Package).Where(p => p.PackageId == model.PackageId);
|
||||||
|
|
||||||
|
model.Versions = await applicationDbContext.ToListAsync();
|
||||||
|
|
||||||
|
return View(model);
|
||||||
|
}
|
||||||
|
|
||||||
|
// GET: PackageVersion/Details/5
|
||||||
|
public async Task<IActionResult> Details(string pkgid, string version)
|
||||||
|
{
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
|
||||||
|
return View(packageVersion);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Authorize]
|
||||||
|
public async Task<IActionResult> Delete(string pkgid, string version)
|
||||||
|
{
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!IsOwner(packageVersion)) return Unauthorized();
|
||||||
|
|
||||||
|
return View(packageVersion);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool IsOwner(PackageVersion v)
|
||||||
|
{
|
||||||
|
var userId = User.FindFirstValue(ClaimTypes.NameIdentifier);
|
||||||
|
return v.Package.OwnerId == userId;
|
||||||
|
}
|
||||||
|
|
||||||
|
// POST: PackageVersion/Delete/5
|
||||||
|
[HttpPost, ActionName("Delete")]
|
||||||
|
[ValidateAntiForgeryToken]
|
||||||
|
public async Task<IActionResult> DeleteConfirmed(string PackageId, string FullString)
|
||||||
|
{
|
||||||
|
var packageVersion = await _context.PackageVersions.Include(p => p.Package)
|
||||||
|
.FirstOrDefaultAsync(m => m.PackageId == PackageId && m.FullString == FullString);
|
||||||
|
if (packageVersion == null) return NotFound();
|
||||||
|
if (!IsOwner(packageVersion)) return Unauthorized();
|
||||||
|
|
||||||
|
_context.PackageVersions.Remove(packageVersion);
|
||||||
|
await _context.SaveChangesAsync();
|
||||||
|
return RedirectToAction(nameof(Index));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,11 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using nuget_host.Data;
|
||||||
|
|
||||||
|
namespace nuget_host.ViewModels
|
||||||
|
{
|
||||||
|
public class PackageVersionIndexViewModel
|
||||||
|
{
|
||||||
|
public List<PackageVersion> Versions {get; set;}
|
||||||
|
public string PackageId { get; set; }
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,52 @@
|
|||||||
|
@model nuget_host.Data.PackageVersion
|
||||||
|
|
||||||
|
@{
|
||||||
|
ViewData["Title"] = "Delete";
|
||||||
|
}
|
||||||
|
|
||||||
|
<h2>Delete</h2>
|
||||||
|
|
||||||
|
<h3>Are you sure you want to delete this?</h3>
|
||||||
|
<div>
|
||||||
|
<h4>PackageVersion</h4>
|
||||||
|
<hr />
|
||||||
|
<dl class="dl-horizontal">
|
||||||
|
<dt>
|
||||||
|
@Html.DisplayNameFor(model => model.Major)
|
||||||
|
</dt>
|
||||||
|
<dd>
|
||||||
|
@Html.DisplayFor(model => model.Major)
|
||||||
|
</dd>
|
||||||
|
<dt>
|
||||||
|
@Html.DisplayNameFor(model => model.Minor)
|
||||||
|
</dt>
|
||||||
|
<dd>
|
||||||
|
@Html.DisplayFor(model => model.Minor)
|
||||||
|
</dd>
|
||||||
|
<dt>
|
||||||
|
@Html.DisplayNameFor(model => model.Patch)
|
||||||
|
</dt>
|
||||||
|
<dd>
|
||||||
|
@Html.DisplayFor(model => model.Patch)
|
||||||
|
</dd>
|
||||||
|
<dt>
|
||||||
|
@Html.DisplayNameFor(model => model.IsPrerelease)
|
||||||
|
</dt>
|
||||||
|
<dd>
|
||||||
|
@Html.DisplayFor(model => model.IsPrerelease)
|
||||||
|
</dd>
|
||||||
|
<dt>
|
||||||
|
@Html.DisplayNameFor(model => model.Package)
|
||||||
|
</dt>
|
||||||
|
<dd>
|
||||||
|
@Html.DisplayFor(model => model.Package.Id)
|
||||||
|
</dd>
|
||||||
|
</dl>
|
||||||
|
|
||||||
|
<form asp-action="Delete">
|
||||||
|
<input type="hidden" asp-for="PackageId" />
|
||||||
|
<input type="hidden" asp-for="FullString" />
|
||||||
|
<input type="submit" value="Delete" class="btn btn-default" /> |
|
||||||
|
<a asp-action="Index">Back to List</a>
|
||||||
|
</form>
|
||||||
|
</div>
|
@ -0,0 +1,48 @@
|
|||||||
|
@model nuget_host.Data.PackageVersion
|
||||||
|
|
||||||
|
@{
|
||||||
|
ViewData["Title"] = "Details";
|
||||||
|
}
|
||||||
|
|
||||||
|
<h2>Details</h2>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<h4>PackageVersion</h4>
|
||||||
|
<hr />
|
||||||
|
<dl class="dl-horizontal">
|
||||||
|
<dt>
|
||||||
|
@Html.DisplayNameFor(model => model.Major)
|
||||||
|
</dt>
|
||||||
|
<dd>
|
||||||
|
@Html.DisplayFor(model => model.Major)
|
||||||
|
</dd>
|
||||||
|
<dt>
|
||||||
|
@Html.DisplayNameFor(model => model.Minor)
|
||||||
|
</dt>
|
||||||
|
<dd>
|
||||||
|
@Html.DisplayFor(model => model.Minor)
|
||||||
|
</dd>
|
||||||
|
<dt>
|
||||||
|
@Html.DisplayNameFor(model => model.Patch)
|
||||||
|
</dt>
|
||||||
|
<dd>
|
||||||
|
@Html.DisplayFor(model => model.Patch)
|
||||||
|
</dd>
|
||||||
|
<dt>
|
||||||
|
@Html.DisplayNameFor(model => model.IsPrerelease)
|
||||||
|
</dt>
|
||||||
|
<dd>
|
||||||
|
@Html.DisplayFor(model => model.IsPrerelease)
|
||||||
|
</dd>
|
||||||
|
<dt>
|
||||||
|
@Html.DisplayNameFor(model => model.Package)
|
||||||
|
</dt>
|
||||||
|
<dd>
|
||||||
|
@Html.DisplayFor(model => model.Package.Id)
|
||||||
|
</dd>
|
||||||
|
</dl>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
@Html.ActionLink("Edit", "Edit", new { /* id = Model.PrimaryKey */ }) |
|
||||||
|
<a asp-action="Index">Back to List</a>
|
||||||
|
</div>
|
@ -0,0 +1,66 @@
|
|||||||
|
@model PackageVersionIndexViewModel
|
||||||
|
|
||||||
|
@{
|
||||||
|
ViewData["Title"] = "Index";
|
||||||
|
}
|
||||||
|
|
||||||
|
<h2>Index</h2>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
<form method="get">
|
||||||
|
<div asp-validation-summary="ModelOnly" class="text-danger"></div>
|
||||||
|
|
||||||
|
<div class="form-group">
|
||||||
|
<label asp-for="PackageId" class="control-label"></label>
|
||||||
|
<input asp-for="PackageId" class="form-control" />
|
||||||
|
</div>
|
||||||
|
<div class="form-group">
|
||||||
|
<input type="submit" value="Find" class="btn btn-default" />
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<table class="table">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>
|
||||||
|
@Html.DisplayNameFor(model => model.Versions[0].Major)
|
||||||
|
</th>
|
||||||
|
<th>
|
||||||
|
@Html.DisplayNameFor(model => model.Versions[0].Minor)
|
||||||
|
</th>
|
||||||
|
<th>
|
||||||
|
@Html.DisplayNameFor(model => model.Versions[0].Patch)
|
||||||
|
</th>
|
||||||
|
<th>
|
||||||
|
@Html.DisplayNameFor(model => model.Versions[0].IsPrerelease)
|
||||||
|
</th>
|
||||||
|
<th>
|
||||||
|
@Html.DisplayNameFor(model => model.Versions[0].Package)
|
||||||
|
</th>
|
||||||
|
<th></th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
@foreach (var item in Model.Versions) {
|
||||||
|
<tr>
|
||||||
|
<td>
|
||||||
|
@Html.DisplayFor(modelItem => item.Major)
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
@Html.DisplayFor(modelItem => item.Minor)
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
@Html.DisplayFor(modelItem => item.Patch)
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
@Html.DisplayFor(modelItem => item.IsPrerelease)
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
@Html.ActionLink("Details", "Details", new { pkgid = Model.PackageId, version = item.FullString }) |
|
||||||
|
@Html.ActionLink("Delete", "Delete", new { pkgid = Model.PackageId, version = item.FullString })
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
@ -1,2 +1,3 @@
|
|||||||
@using nuget_host.Data
|
@using nuget_host.Data
|
||||||
|
@using nuget_host.ViewModels
|
||||||
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
|
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
|
||||||
|
Binary file not shown.
Loading…
Reference in New Issue