pkg upd by no db

broken/ef
Paul Schneider 3 years ago
parent bd1c47e7c6
commit 58750587d0
4 changed files with 42 additions and 12 deletions

@ -22,10 +22,10 @@ namespace isn
// GET: PackageVersion // GET: PackageVersion
public async Task<IActionResult> Index(PackageVersionIndexViewModel model) public async Task<IActionResult> Index(PackageVersionIndexViewModel model)
{ {
var applicationDbContext = _context.PackageVersions.Include(p => p.Package).Where(p => p.PackageId.StartsWith(model.PackageId)); var applicationDbContext = _context.PackageVersions.Include(p => p.Package).Where(
p => ( model.Prerelease || p.IsPrerelease)
&& ((model.PackageId == null) || p.PackageId.StartsWith(model.PackageId)));
model.Versions = await applicationDbContext.ToArrayAsync(); model.Versions = await applicationDbContext.ToArrayAsync();
return View(model); return View(model);
} }

@ -104,14 +104,26 @@ namespace isn.Controllers
var destdir = new DirectoryInfo(dest.DirectoryName); var destdir = new DirectoryInfo(dest.DirectoryName);
if (dest.Exists) if (dest.Exists)
{ {
ViewData["msg"] = "existant"; // La version existe sur le disque,
ViewData["ecode"] = 1; // mais si elle ne l'est pas en base de donnéés,
_logger.LogWarning("400 : existant"); // on remplace la version sur disque.
return base.BadRequest(new { error = ModelState }); var pkgv = _dbContext.PackageVersions.Where(
v => v.PackageId == package.Id
);
if (pkgv !=null && pkgv.Count()==0)
{
dest.Delete();
}
else {
ViewData["msg"] = "existant";
ViewData["ecode"] = 1;
_logger.LogWarning("400 : existant");
return base.BadRequest(new { error = ModelState });
}
} }
else
{ {
destdir.Create(); if (!destdir.Exists) destdir.Create();
source.MoveTo(fullpath); source.MoveTo(fullpath);
files.Add(name); files.Add(name);
string fullstringversion = version.ToFullString(); string fullstringversion = version.ToFullString();
@ -156,7 +168,12 @@ namespace isn.Controllers
} }
} }
} }
nuspec.ExtractToFile(Path.Combine(pkgpath, pkgid + ".nuspec")); string nuspecfullpath = Path.Combine(pkgpath, pkgid + ".nuspec");
FileInfo nfpi = new FileInfo(nuspecfullpath);
if (nfpi.Exists)
nfpi.Delete();
nuspec.ExtractToFile(nuspecfullpath);
} }
} }

@ -2,6 +2,8 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using isn.Controllers; using isn.Controllers;
using isn.Data; using isn.Data;
using isn.ViewModels;
using isnd.ViewModels;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using NuGet.Versioning; using NuGet.Versioning;
using Unleash; using Unleash;
@ -15,7 +17,7 @@ namespace isnd.Services
{ {
this.dbContext = dbContext; this.dbContext = dbContext;
} }
public IndexResult SearchByName(string query, public PackageIndexViewModel SearchByName(string query,
int skip, int take,bool prerelease = false, int skip, int take,bool prerelease = false,
string packageType = null) string packageType = null)
{ {
@ -30,7 +32,7 @@ namespace isnd.Services
var total = scope.Count(); var total = scope.Count();
var pkgs = scope.Skip(skip).Take(take).ToArray(); var pkgs = scope.Skip(skip).Take(take).ToArray();
return new IndexResult return new PackageIndexViewModel
{ {
totalHits = total, totalHits = total,
data = pkgs data = pkgs

@ -0,0 +1,11 @@
using isn.Data;
namespace isnd.ViewModels
{
public class PackageIndexViewModel
{
public Package[] data {get; set;}
public string Query { get; set; }
public int totalHits { get; internal set; }
}
}
Loading…