public async Task <IActionResult> AddSyndicationFeed([FromForm] PackageGroupAssociation groupAssociation) { if (string.IsNullOrEmpty(groupAssociation.Group) || string.IsNullOrEmpty(groupAssociation.Feed)) { return(PackageGroups()); } var group = await _dbContext.PackageGroups .Include(x => x.Members) .Include(x => x.Syndications) .FirstOrDefaultAsync(x => x.Name == groupAssociation.Group); if (group is null || group.Syndications.Any(x => x.PublishTargetName == groupAssociation.Feed)) { return(PackageGroups()); } _dbContext.Syndications.Add(new PackageGroupSyndication { PackageGroupName = group.Name, PublishTargetName = groupAssociation.Feed }); await _dbContext.SaveChangesAsync(); return(PackageGroups()); }
public async Task <IActionResult> AddPackageToGroup([FromForm] PackageGroupAssociation groupAssociation) { if (string.IsNullOrEmpty(groupAssociation.Group) || string.IsNullOrEmpty(groupAssociation.PackageId)) { return(PackageGroups()); } var group = await _dbContext.PackageGroups .Include(x => x.Members) .Include(x => x.Syndications) .FirstOrDefaultAsync(x => x.Name == groupAssociation.Group); if (group is null || group.Members.Any(x => x.PackageId == groupAssociation.PackageId)) { return(PackageGroups()); } if (!await _context.Packages.AnyAsync(x => x.Id == groupAssociation.PackageId)) { return(PackageGroups()); } _dbContext.PackageGroupMembers.Add(new PackageGroupMember { PackageGroupName = group.Name, PackageId = groupAssociation.PackageId }); await _dbContext.SaveChangesAsync(); return(PackageGroups()); }
public async Task <IActionResult> PushLatest(string groupName, [FromForm] PackageGroupAssociation groupAssociation, [FromServices] IPackageStorageService packageStorage, [FromServices] ISymbolStorageService symbolStorage) { if (groupName != groupAssociation.Group) { return(PackageGroups()); } var group = await _dbContext.PackageGroups .Include(x => x.Members) .Include(x => x.Syndications) .ThenInclude(x => x.PublishTarget) .FirstOrDefaultAsync(x => x.Name == groupName); if (group is null) { return(PackageGroups()); } var targets = group.Syndications.Select(x => x.PublishTarget); foreach (var package in group.Members) { var nugetPackage = await _context.Packages.Where(x => x.Id == package.PackageId && x.Listed == true) .OrderByDescending(x => x.Version) .FirstOrDefaultAsync(); if (nugetPackage is null) { continue; } foreach (var targetFeed in targets) { var client = new NuGetClient(targetFeed.PublishEndpoint.ToString()); await client.UploadPackageAsync(nugetPackage.Id, nugetPackage.Version, targetFeed.ApiToken, packageStorage); await client.UploadSymbolsPackageAsync(nugetPackage.Id, nugetPackage.Version, targetFeed.ApiToken, symbolStorage); } } // TODO: Add Success Page return(PackageGroups()); }