broken/ef
Paul Schneider 3 years ago
parent 9575dd2754
commit e4511a8aaa
38 changed files with 615 additions and 68 deletions

@ -6,7 +6,7 @@ using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Mvc;
using nuget_host.Models;
using nuget_host.Data;
using System;
using System.Linq;
using System.Threading.Tasks;

@ -12,8 +12,8 @@ using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Options;
using nuget_host.Data;
using nuget_host.Entities;
using nuget_host.Models;
using nuget_host.Models.ApiKeys;
using nuget_host.Data;
using nuget_host.Data.ApiKeys;
namespace nuget_host.Controllers

@ -5,7 +5,7 @@ using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using nuget_host.Entities;
using nuget_host.Models;
using nuget_host.Data;
namespace nuget_host.Controllers
{

@ -4,6 +4,7 @@ using System.IO;
using System.IO.Compression;
using System.Linq;
using System.Security.Claims;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.DataProtection;
using Microsoft.AspNetCore.Mvc;
@ -40,27 +41,29 @@ namespace nuget_host.Controllers
}
[HttpPut("packages")]
public IActionResult Put()
public async Task<IActionResult> Put()
{
string path = null;
var clientVersionId = Request.Headers["X-NuGet-Client-Version"];
var apiKey = Request.Headers["X-NuGet-ApiKey"];
ViewData["clientVersionId"] = clientVersionId;
ViewData["versionId"] = typeof(PackagesController).Assembly.FullName;
var files = new List<string>();
ViewData["files"] = files;
var clearkey = protector.Unprotect(apiKey);
var apikey = dbContext.ApiKeys.SingleOrDefault(k => k.Id == clearkey);
if (apikey == null)
return new BadRequestObjectResult(new { error = "api-key" });
return Unauthorized();
foreach (var file in Request.Form.Files)
{
try
{
files.Add(file.Name);
string initpath = file.Name;
string initpath = Path.Combine(Environment.GetEnvironmentVariable("TEMP"),
$"nuget_host-{Guid.NewGuid()}.nupkg");
using (FileStream fw = new FileStream(initpath, FileMode.Create))
{
file.CopyTo(fw);
@ -86,15 +89,66 @@ namespace nuget_host.Controllers
Path.Combine(pkgid,
Path.Combine(version.Version.ToString()),
$"{pkgid}-{version}.nupkg"));
var source = new FileInfo(initpath);
var dest = new FileInfo(path);
var destdir = new DirectoryInfo(dest.DirectoryName);
if (dest.Exists)
return BadRequest(new { error = "existant" });
if (!destdir.Exists) destdir.Create();
source.MoveTo(path);
logger.LogWarning($"200: {entry.Name}");
if (!destdir.Exists)
{
destdir.Create();
source.MoveTo(path);
var newpkg = new Package
{
Id = pkgid,
Description = pkgdesc,
OwnerId = apikey.UserId
};
dbContext.Packages.Add(newpkg);
var newversion = new PackageVersion
{
Package = newpkg,
Major = version.Major,
Minor = version.Minor,
Patch = version.Patch,
IsPrerelease = version.IsPrerelease,
FullString = version.ToFullString()
};
dbContext.PackageVersions.Add(newversion);
await dbContext.SaveChangesAsync();
logger.LogInformation($"new package : {entry.Name}");
}
else
{
var pkg = dbContext.Packages.SingleOrDefault(p => p.Id == pkgid);
if (pkg == null)
{
// TODO Choose an app policy to take ownership
// on existing package on disk.
throw new Exception("Package directory exists, but don't have any owner");
}
if (apikey.UserId != pkg.OwnerId)
return Unauthorized();
var newversion = new PackageVersion
{
PackageId = pkg.Id,
Major = version.Major,
Minor = version.Minor,
Patch = version.Patch,
IsPrerelease = version.IsPrerelease,
FullString = version.ToFullString()
};
dbContext.PackageVersions.Add(newversion);
await dbContext.SaveChangesAsync();
logger.LogInformation($"new version : {entry.Name}");
}
}
}
}

@ -4,7 +4,7 @@
using System;
namespace nuget_host.Models
namespace nuget_host.Data
{
public class AccountOptions
{

@ -2,7 +2,7 @@
// Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information.
namespace nuget_host.Models
namespace nuget_host.Data
{
public class ExternalProvider
{

@ -2,7 +2,7 @@
// Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information.
namespace nuget_host.Models
namespace nuget_host.Data
{
public class LoggedOutViewModel
{

@ -4,7 +4,7 @@
using System.ComponentModel.DataAnnotations;
namespace nuget_host.Models
namespace nuget_host.Data
{
public class LoginInputModel
{

@ -6,7 +6,7 @@ using System;
using System.Collections.Generic;
using System.Linq;
namespace nuget_host.Models
namespace nuget_host.Data
{
public class LoginViewModel : LoginInputModel
{

@ -2,7 +2,7 @@
// Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information.
namespace nuget_host.Models
namespace nuget_host.Data
{
public class LogoutInputModel
{

@ -2,7 +2,7 @@
// Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information.
namespace nuget_host.Models
namespace nuget_host.Data
{
public class LogoutViewModel : LogoutInputModel
{

@ -3,7 +3,7 @@
namespace nuget_host.Models
namespace nuget_host.Data
{
public class RedirectViewModel
{

@ -4,7 +4,7 @@ using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Threading.Tasks;
namespace nuget_host.Models
namespace nuget_host.Data
{
public class RegisterViewModel
{

@ -2,7 +2,7 @@ using System;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace nuget_host.Models.ApiKeys
namespace nuget_host.Data.ApiKeys
{
public class ApiKey
{

@ -1,6 +1,6 @@
using System.ComponentModel.DataAnnotations;
namespace nuget_host.Models.ApiKeys
namespace nuget_host.Data.ApiKeys
{
public class ApiKeyViewModel
{

@ -1,6 +1,6 @@
using System.ComponentModel.DataAnnotations;
namespace nuget_host.Models.ApiKeys
namespace nuget_host.Data.ApiKeys
{
public class CreateModel
{

@ -1,4 +1,4 @@
namespace nuget_host.Models.ApiKeys
namespace nuget_host.Data.ApiKeys
{
public class DeleteModel
{

@ -1,4 +1,4 @@
namespace nuget_host.Models.ApiKeys
namespace nuget_host.Data.ApiKeys
{
public class DetailModel : ApiKeyViewModel
{

@ -1,4 +1,4 @@
namespace nuget_host.Models.ApiKeys
namespace nuget_host.Data.ApiKeys
{
public class EditModel
{

@ -1,6 +1,6 @@
using System.Collections.Generic;
namespace nuget_host.Models.ApiKeys
namespace nuget_host.Data.ApiKeys
{
public class IndexModel
{

@ -3,8 +3,8 @@ using System.Collections.Generic;
using System.Text;
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore;
using nuget_host.Models;
using nuget_host.Models.ApiKeys;
using nuget_host.Data;
using nuget_host.Data.ApiKeys;
namespace nuget_host.Data
{
@ -14,7 +14,9 @@ namespace nuget_host.Data
: base(options)
{
}
public DbSet<ApiKey> ApiKeys { get; set; }
public DbSet<Package> Packages { get; set; }
public DbSet<PackageVersion> PackageVersions { get; set; }
}
}

@ -1,6 +1,6 @@
using Microsoft.AspNetCore.Identity;
namespace nuget_host.Models
namespace nuget_host.Data
{
// Add profile data for application users by adding properties to the ApplicationUser class
public class ApplicationUser : IdentityUser

@ -0,0 +1,18 @@
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace nuget_host.Data
{
public class Package
{
[Key][Required]
public string Id { get; set; }
[Required]
[ForeignKey("Owner")]
public string OwnerId { get; set; }
public string Description { get; set; }
virtual public ApplicationUser Owner { get; set; }
}
}

@ -0,0 +1,30 @@
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace nuget_host.Data
{
public class PackageVersion
{
[Required]
[ForeignKey("Package")]
public string PackageId { get; set; }
[Required]
public int Major { get; set; }
[Required]
public int Minor { get; set; }
[Required]
public int Patch { get; set; }
[StringLength(32)]
[Required][Key]
public string FullString { get; set; }
public bool IsPrerelease { get; set; }
public virtual Package Package { get; set; }
}
}

@ -1,7 +1,7 @@
using System;
using Microsoft.AspNetCore.Mvc;
namespace nuget_host.Models
namespace nuget_host.Data
{
public static class Extensions
{

@ -128,7 +128,7 @@ namespace nugethost.Migrations
b.ToTable("AspNetUserTokens");
});
modelBuilder.Entity("nuget_host.Models.ApplicationUser", b =>
modelBuilder.Entity("nuget_host.Data.ApplicationUser", b =>
{
b.Property<string>("Id")
.ValueGeneratedOnAdd();
@ -190,7 +190,7 @@ namespace nugethost.Migrations
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim<string>", b =>
{
b.HasOne("nuget_host.Models.ApplicationUser")
b.HasOne("nuget_host.Data.ApplicationUser")
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade);
@ -198,7 +198,7 @@ namespace nugethost.Migrations
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin<string>", b =>
{
b.HasOne("nuget_host.Models.ApplicationUser")
b.HasOne("nuget_host.Data.ApplicationUser")
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade);
@ -211,7 +211,7 @@ namespace nugethost.Migrations
.HasForeignKey("RoleId")
.OnDelete(DeleteBehavior.Cascade);
b.HasOne("nuget_host.Models.ApplicationUser")
b.HasOne("nuget_host.Data.ApplicationUser")
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade);
@ -219,7 +219,7 @@ namespace nugethost.Migrations
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken<string>", b =>
{
b.HasOne("nuget_host.Models.ApplicationUser")
b.HasOne("nuget_host.Data.ApplicationUser")
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade);

@ -128,7 +128,7 @@ namespace nugethost.Migrations
b.ToTable("AspNetUserTokens");
});
modelBuilder.Entity("nuget_host.Models.ApiKey", b =>
modelBuilder.Entity("nuget_host.Data.ApiKey", b =>
{
b.Property<string>("Id")
.ValueGeneratedOnAdd();
@ -143,7 +143,7 @@ namespace nugethost.Migrations
b.ToTable("ApiKeys");
});
modelBuilder.Entity("nuget_host.Models.ApplicationUser", b =>
modelBuilder.Entity("nuget_host.Data.ApplicationUser", b =>
{
b.Property<string>("Id")
.ValueGeneratedOnAdd();
@ -205,7 +205,7 @@ namespace nugethost.Migrations
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim<string>", b =>
{
b.HasOne("nuget_host.Models.ApplicationUser")
b.HasOne("nuget_host.Data.ApplicationUser")
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade);
@ -213,7 +213,7 @@ namespace nugethost.Migrations
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin<string>", b =>
{
b.HasOne("nuget_host.Models.ApplicationUser")
b.HasOne("nuget_host.Data.ApplicationUser")
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade);
@ -226,7 +226,7 @@ namespace nugethost.Migrations
.HasForeignKey("RoleId")
.OnDelete(DeleteBehavior.Cascade);
b.HasOne("nuget_host.Models.ApplicationUser")
b.HasOne("nuget_host.Data.ApplicationUser")
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade);
@ -234,15 +234,15 @@ namespace nugethost.Migrations
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken<string>", b =>
{
b.HasOne("nuget_host.Models.ApplicationUser")
b.HasOne("nuget_host.Data.ApplicationUser")
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade);
});
modelBuilder.Entity("nuget_host.Models.ApiKey", b =>
modelBuilder.Entity("nuget_host.Data.ApiKey", b =>
{
b.HasOne("nuget_host.Models.ApplicationUser", "User")
b.HasOne("nuget_host.Data.ApplicationUser", "User")
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade);

@ -128,7 +128,7 @@ namespace nugethost.Migrations
b.ToTable("AspNetUserTokens");
});
modelBuilder.Entity("nuget_host.Models.ApiKeys.ApiKey", b =>
modelBuilder.Entity("nuget_host.Data.ApiKeys.ApiKey", b =>
{
b.Property<string>("Id")
.ValueGeneratedOnAdd();
@ -149,7 +149,7 @@ namespace nugethost.Migrations
b.ToTable("ApiKeys");
});
modelBuilder.Entity("nuget_host.Models.ApplicationUser", b =>
modelBuilder.Entity("nuget_host.Data.ApplicationUser", b =>
{
b.Property<string>("Id")
.ValueGeneratedOnAdd();
@ -211,7 +211,7 @@ namespace nugethost.Migrations
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim<string>", b =>
{
b.HasOne("nuget_host.Models.ApplicationUser")
b.HasOne("nuget_host.Data.ApplicationUser")
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade);
@ -219,7 +219,7 @@ namespace nugethost.Migrations
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin<string>", b =>
{
b.HasOne("nuget_host.Models.ApplicationUser")
b.HasOne("nuget_host.Data.ApplicationUser")
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade);
@ -232,7 +232,7 @@ namespace nugethost.Migrations
.HasForeignKey("RoleId")
.OnDelete(DeleteBehavior.Cascade);
b.HasOne("nuget_host.Models.ApplicationUser")
b.HasOne("nuget_host.Data.ApplicationUser")
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade);
@ -240,15 +240,15 @@ namespace nugethost.Migrations
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken<string>", b =>
{
b.HasOne("nuget_host.Models.ApplicationUser")
b.HasOne("nuget_host.Data.ApplicationUser")
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade);
});
modelBuilder.Entity("nuget_host.Models.ApiKeys.ApiKey", b =>
modelBuilder.Entity("nuget_host.Data.ApiKeys.ApiKey", b =>
{
b.HasOne("nuget_host.Models.ApplicationUser", "User")
b.HasOne("nuget_host.Data.ApplicationUser", "User")
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade);

@ -0,0 +1,316 @@
// <auto-generated />
using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
using nuget_host.Data;
namespace nugethost.Migrations
{
[DbContext(typeof(ApplicationDbContext))]
[Migration("20210516060430_packages")]
partial class packages
{
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.SerialColumn)
.HasAnnotation("ProductVersion", "2.2.6-servicing-10079")
.HasAnnotation("Relational:MaxIdentifierLength", 63);
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRole", b =>
{
b.Property<string>("Id")
.ValueGeneratedOnAdd();
b.Property<string>("ConcurrencyStamp")
.IsConcurrencyToken();
b.Property<string>("Name")
.HasMaxLength(256);
b.Property<string>("NormalizedName")
.HasMaxLength(256);
b.HasKey("Id");
b.HasIndex("NormalizedName")
.IsUnique()
.HasName("RoleNameIndex");
b.ToTable("AspNetRoles");
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim<string>", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd();
b.Property<string>("ClaimType");
b.Property<string>("ClaimValue");
b.Property<string>("RoleId")
.IsRequired();
b.HasKey("Id");
b.HasIndex("RoleId");
b.ToTable("AspNetRoleClaims");
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim<string>", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd();
b.Property<string>("ClaimType");
b.Property<string>("ClaimValue");
b.Property<string>("UserId")
.IsRequired();
b.HasKey("Id");
b.HasIndex("UserId");
b.ToTable("AspNetUserClaims");
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin<string>", b =>
{
b.Property<string>("LoginProvider");
b.Property<string>("ProviderKey");
b.Property<string>("ProviderDisplayName");
b.Property<string>("UserId")
.IsRequired();
b.HasKey("LoginProvider", "ProviderKey");
b.HasIndex("UserId");
b.ToTable("AspNetUserLogins");
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole<string>", b =>
{
b.Property<string>("UserId");
b.Property<string>("RoleId");
b.HasKey("UserId", "RoleId");
b.HasIndex("RoleId");
b.ToTable("AspNetUserRoles");
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken<string>", b =>
{
b.Property<string>("UserId");
b.Property<string>("LoginProvider");
b.Property<string>("Name");
b.Property<string>("Value");
b.HasKey("UserId", "LoginProvider", "Name");
b.ToTable("AspNetUserTokens");
});
modelBuilder.Entity("nuget_host.Data.ApiKeys.ApiKey", b =>
{
b.Property<string>("Id")
.ValueGeneratedOnAdd();
b.Property<DateTime>("CreationDate");
b.Property<string>("Name");
b.Property<string>("UserId")
.IsRequired();
b.Property<int>("ValidityPeriodInDays");
b.HasKey("Id");
b.HasIndex("UserId");
b.ToTable("ApiKeys");
});
modelBuilder.Entity("nuget_host.Data.ApplicationUser", b =>
{
b.Property<string>("Id")
.ValueGeneratedOnAdd();
b.Property<int>("AccessFailedCount");
b.Property<string>("ConcurrencyStamp")
.IsConcurrencyToken();
b.Property<string>("Email")
.HasMaxLength(256);
b.Property<bool>("EmailConfirmed");
b.Property<string>("FullName");
b.Property<bool>("LockoutEnabled");
b.Property<DateTimeOffset?>("LockoutEnd");
b.Property<string>("NormalizedEmail")
.HasMaxLength(256);
b.Property<string>("NormalizedUserName")
.HasMaxLength(256);
b.Property<string>("PasswordHash");
b.Property<string>("PhoneNumber");
b.Property<bool>("PhoneNumberConfirmed");
b.Property<string>("SecurityStamp");
b.Property<bool>("TwoFactorEnabled");
b.Property<string>("UserName")
.HasMaxLength(256);
b.HasKey("Id");
b.HasIndex("NormalizedEmail")
.HasName("EmailIndex");
b.HasIndex("NormalizedUserName")
.IsUnique()
.HasName("UserNameIndex");
b.ToTable("AspNetUsers");
});
modelBuilder.Entity("nuget_host.Data.Package", b =>
{
b.Property<string>("Id")
.ValueGeneratedOnAdd();
b.Property<string>("Description");
b.Property<string>("OwnerId")
.IsRequired();
b.HasKey("Id");
b.HasIndex("OwnerId");
b.ToTable("Packages");
});
modelBuilder.Entity("nuget_host.Data.PackageVersion", b =>
{
b.Property<string>("FullString")
.ValueGeneratedOnAdd()
.HasMaxLength(32);
b.Property<bool>("IsPrerelease");
b.Property<int>("Major");
b.Property<int>("Minor");
b.Property<string>("PackageId")
.IsRequired();
b.Property<int>("Patch");
b.HasKey("FullString");
b.HasIndex("PackageId");
b.ToTable("PackageVersions");
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim<string>", b =>
{
b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole")
.WithMany()
.HasForeignKey("RoleId")
.OnDelete(DeleteBehavior.Cascade);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim<string>", b =>
{
b.HasOne("nuget_host.Data.ApplicationUser")
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin<string>", b =>
{
b.HasOne("nuget_host.Data.ApplicationUser")
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole<string>", b =>
{
b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole")
.WithMany()
.HasForeignKey("RoleId")
.OnDelete(DeleteBehavior.Cascade);
b.HasOne("nuget_host.Data.ApplicationUser")
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken<string>", b =>
{
b.HasOne("nuget_host.Data.ApplicationUser")
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade);
});
modelBuilder.Entity("nuget_host.Data.ApiKeys.ApiKey", b =>
{
b.HasOne("nuget_host.Data.ApplicationUser", "User")
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade);
});
modelBuilder.Entity("nuget_host.Data.Package", b =>
{
b.HasOne("nuget_host.Data.ApplicationUser", "Owner")
.WithMany()
.HasForeignKey("OwnerId")
.OnDelete(DeleteBehavior.Cascade);
});
modelBuilder.Entity("nuget_host.Data.PackageVersion", b =>
{
b.HasOne("nuget_host.Data.Package", "Package")
.WithMany()
.HasForeignKey("PackageId")
.OnDelete(DeleteBehavior.Cascade);
});
#pragma warning restore 612, 618
}
}
}

@ -0,0 +1,70 @@
using Microsoft.EntityFrameworkCore.Migrations;
namespace nugethost.Migrations
{
public partial class packages : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "Packages",
columns: table => new
{
Id = table.Column<string>(nullable: false),
OwnerId = table.Column<string>(nullable: false),
Description = table.Column<string>(nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_Packages", x => x.Id);
table.ForeignKey(
name: "FK_Packages_AspNetUsers_OwnerId",
column: x => x.OwnerId,
principalTable: "AspNetUsers",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "PackageVersions",
columns: table => new
{
FullString = table.Column<string>(maxLength: 32, nullable: false),
PackageId = table.Column<string>(nullable: false),
Major = table.Column<int>(nullable: false),
Minor = table.Column<int>(nullable: false),
Patch = table.Column<int>(nullable: false),
IsPrerelease = table.Column<bool>(nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_PackageVersions", x => x.FullString);
table.ForeignKey(
name: "FK_PackageVersions_Packages_PackageId",
column: x => x.PackageId,
principalTable: "Packages",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateIndex(
name: "IX_Packages_OwnerId",
table: "Packages",
column: "OwnerId");
migrationBuilder.CreateIndex(
name: "IX_PackageVersions_PackageId",
table: "PackageVersions",
column: "PackageId");
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "PackageVersions");
migrationBuilder.DropTable(
name: "Packages");
}
}
}

@ -126,7 +126,7 @@ namespace nugethost.Migrations
b.ToTable("AspNetUserTokens");
});
modelBuilder.Entity("nuget_host.Models.ApiKeys.ApiKey", b =>
modelBuilder.Entity("nuget_host.Data.ApiKeys.ApiKey", b =>
{
b.Property<string>("Id")
.ValueGeneratedOnAdd();
@ -147,7 +147,7 @@ namespace nugethost.Migrations
b.ToTable("ApiKeys");
});
modelBuilder.Entity("nuget_host.Models.ApplicationUser", b =>
modelBuilder.Entity("nuget_host.Data.ApplicationUser", b =>
{
b.Property<string>("Id")
.ValueGeneratedOnAdd();
@ -199,6 +199,47 @@ namespace nugethost.Migrations
b.ToTable("AspNetUsers");
});
modelBuilder.Entity("nuget_host.Data.Package", b =>
{
b.Property<string>("Id")
.ValueGeneratedOnAdd();
b.Property<string>("Description");
b.Property<string>("OwnerId")
.IsRequired();
b.HasKey("Id");
b.HasIndex("OwnerId");
b.ToTable("Packages");
});
modelBuilder.Entity("nuget_host.Data.PackageVersion", b =>
{
b.Property<string>("FullString")
.ValueGeneratedOnAdd()
.HasMaxLength(32);
b.Property<bool>("IsPrerelease");
b.Property<int>("Major");
b.Property<int>("Minor");
b.Property<string>("PackageId")
.IsRequired();
b.Property<int>("Patch");
b.HasKey("FullString");
b.HasIndex("PackageId");
b.ToTable("PackageVersions");
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim<string>", b =>
{
b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole")
@ -209,7 +250,7 @@ namespace nugethost.Migrations
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim<string>", b =>
{
b.HasOne("nuget_host.Models.ApplicationUser")
b.HasOne("nuget_host.Data.ApplicationUser")
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade);
@ -217,7 +258,7 @@ namespace nugethost.Migrations
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin<string>", b =>
{
b.HasOne("nuget_host.Models.ApplicationUser")
b.HasOne("nuget_host.Data.ApplicationUser")
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade);
@ -230,7 +271,7 @@ namespace nugethost.Migrations
.HasForeignKey("RoleId")
.OnDelete(DeleteBehavior.Cascade);
b.HasOne("nuget_host.Models.ApplicationUser")
b.HasOne("nuget_host.Data.ApplicationUser")
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade);
@ -238,19 +279,35 @@ namespace nugethost.Migrations
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken<string>", b =>
{
b.HasOne("nuget_host.Models.ApplicationUser")
b.HasOne("nuget_host.Data.ApplicationUser")
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade);
});
modelBuilder.Entity("nuget_host.Models.ApiKeys.ApiKey", b =>
modelBuilder.Entity("nuget_host.Data.ApiKeys.ApiKey", b =>
{
b.HasOne("nuget_host.Models.ApplicationUser", "User")
b.HasOne("nuget_host.Data.ApplicationUser", "User")
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade);
});
modelBuilder.Entity("nuget_host.Data.Package", b =>
{
b.HasOne("nuget_host.Data.ApplicationUser", "Owner")
.WithMany()
.HasForeignKey("OwnerId")
.OnDelete(DeleteBehavior.Cascade);
});
modelBuilder.Entity("nuget_host.Data.PackageVersion", b =>
{
b.HasOne("nuget_host.Data.Package", "Package")
.WithMany()
.HasForeignKey("PackageId")
.OnDelete(DeleteBehavior.Cascade);
});
#pragma warning restore 612, 618
}
}

@ -17,7 +17,7 @@ using nuget_host.Data;
using nuget_host.Interfaces;
using nuget_host.Services;
using nuget_host.Entities;
using nuget_host.Models;
using nuget_host.Data;
using System.Reflection;
namespace nuget_host

@ -1,5 +1,5 @@
@model nuget_host.Models.ApiKeys.CreateModel
@model nuget_host.Data.ApiKeys.CreateModel
@{
ViewData["Title"] = "Create";

@ -1,5 +1,5 @@
@model nuget_host.Models.ApiKeys.DeleteModel
@model nuget_host.Data.ApiKeys.DeleteModel
@{
ViewData["Title"] = "Delete";

@ -1,5 +1,5 @@
@model nuget_host.Models.ApiKeys.DetailModel
@model nuget_host.Data.ApiKeys.DetailModel
@{
ViewData["Title"] = "Details";

@ -1,5 +1,5 @@
@model nuget_host.Models.ApiKeys.EditModel
@model nuget_host.Data.ApiKeys.EditModel
@{
ViewData["Title"] = "Edit";

@ -1,5 +1,5 @@
@model nuget_host.Models.ApiKeys.IndexModel
@model nuget_host.Data.ApiKeys.IndexModel
@{
ViewData["Title"] = "Index";

@ -1,2 +1,2 @@
@using nuget_host.Models
@using nuget_host.Data
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers

Loading…