22// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33
44using System ;
5+ using System . Data . Entity ;
56using System . Linq ;
67using System . Web . Mvc ;
78using System . Threading . Tasks ;
@@ -13,19 +14,23 @@ namespace NuGetGallery.Areas.Admin.Controllers
1314{
1415 public class ReservedNamespaceController : AdminControllerBase
1516 {
16- private IReservedNamespaceService _reservedNamespaceService ;
17+ private readonly IReservedNamespaceService _reservedNamespaceService ;
18+ private readonly IEntityRepository < PackageRegistration > _packageRegistrations ;
1719
1820 protected ReservedNamespaceController ( ) { }
1921
20- public ReservedNamespaceController ( IReservedNamespaceService reservedNamespaceService )
22+ public ReservedNamespaceController (
23+ IReservedNamespaceService reservedNamespaceService ,
24+ IEntityRepository < PackageRegistration > packageRegistrations )
2125 {
2226 _reservedNamespaceService = reservedNamespaceService ?? throw new ArgumentNullException ( nameof ( reservedNamespaceService ) ) ;
27+ _packageRegistrations = packageRegistrations ?? throw new ArgumentNullException ( nameof ( packageRegistrations ) ) ;
2328 }
2429
2530 [ HttpGet ]
2631 public ActionResult Index ( )
2732 {
28- return View ( ) ;
33+ return View ( new ReservedNamespaceViewModel ( ) ) ;
2934 }
3035
3136 [ HttpGet ]
@@ -49,6 +54,37 @@ public JsonResult SearchPrefix(string query)
4954 return Json ( results , JsonRequestBehavior . AllowGet ) ;
5055 }
5156
57+ [ HttpGet ]
58+ public ActionResult FindNamespacesByPrefix ( string prefix )
59+ {
60+ var namespaces = _reservedNamespaceService
61+ . FindAllReservedNamespacesForPrefix ( prefix , getExactMatches : false )
62+ . OrderBy ( x => x . Value )
63+ . ThenBy ( x => x . IsPrefix )
64+ . ToList ( ) ;
65+ var model = new ReservedNamespaceViewModel { ReservedNamespacesQuery = prefix , ReservedNamespaces = namespaces } ;
66+ return View ( nameof ( Index ) , model ) ;
67+ }
68+
69+ [ HttpGet ]
70+ public ActionResult FindPackagesByPrefix ( string prefix )
71+ {
72+ if ( string . IsNullOrWhiteSpace ( prefix ) )
73+ {
74+ return RedirectToAction ( nameof ( Index ) ) ;
75+ }
76+
77+ var packageRegistrations = _packageRegistrations
78+ . GetAll ( )
79+ . Include ( x => x . Owners )
80+ . Include ( x => x . ReservedNamespaces )
81+ . Where ( x => x . Id . StartsWith ( prefix ) )
82+ . OrderBy ( x => x . Id )
83+ . ToList ( ) ;
84+ var model = new ReservedNamespaceViewModel { PackageRegistrationsQuery = prefix , PackageRegistrations = packageRegistrations } ;
85+ return View ( nameof ( Index ) , model ) ;
86+ }
87+
5288 [ HttpPost ]
5389 [ ValidateAntiForgeryToken ]
5490 public async Task < JsonResult > AddNamespace ( ReservedNamespace newNamespace )
0 commit comments