i'm not sure what i'm doing

This commit is contained in:
Вячеслав 2025-03-25 22:56:35 +05:00
parent 950babb68c
commit 35331a87f1
7 changed files with 41 additions and 13 deletions

View file

@ -1,3 +1,8 @@
using Microsoft.AspNetCore.Identity;
using Microsoft.EntityFrameworkCore;
using SurveyBackend.Core.Models;
using SurveyBackend.Infrastructure.Data;
namespace SurveyBackend; namespace SurveyBackend;
public class Program public class Program
@ -8,7 +13,16 @@ public class Program
// Add services to the container. // Add services to the container.
builder.Services.AddAuthorization(); builder.Services.AddAuthorization();
builder.Services.AddDbContext<DataContext>(options =>
{
options.UseSqlite(builder.Configuration.GetConnectionString("DefaultConnection"));
});
builder.Services.AddIdentity<User, IdentityRole<int>>(options => { })
.AddEntityFrameworkStores<DataContext>()
.AddDefaultTokenProviders();
builder.Services.AddControllers(); builder.Services.AddControllers();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
@ -25,9 +39,9 @@ public class Program
} }
app.UseAuthorization(); app.UseAuthorization();
app.MapControllers(); app.MapControllers();
app.Run(); app.Run();
} }
} }

View file

@ -9,7 +9,13 @@
<ItemGroup> <ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="8.0.2"/> <PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="8.0.2"/>
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="9.0.3" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.4.0"/> <PackageReference Include="Swashbuckle.AspNetCore" Version="6.4.0"/>
</ItemGroup> </ItemGroup>
<ItemGroup>
<ProjectReference Include="..\SurveyBackend.Core\SurveyBackend.Core.csproj" />
<ProjectReference Include="..\SurveyBackend.Infrastructure\SurveyBackend.Infrastructure.csproj" />
</ItemGroup>
</Project> </Project>

View file

@ -4,5 +4,8 @@
"Default": "Information", "Default": "Information",
"Microsoft.AspNetCore": "Warning" "Microsoft.AspNetCore": "Warning"
} }
},
"ConnectionStrings": {
"DefaultConnection": "Data Source=Application.db"
} }
} }

View file

@ -5,5 +5,8 @@
"Microsoft.AspNetCore": "Warning" "Microsoft.AspNetCore": "Warning"
} }
}, },
"AllowedHosts": "*" "AllowedHosts": "*",
"ConnectionStrings": {
"DefaultConnection": "Data Source=Application.db"
}
} }

View file

@ -1,15 +1,11 @@
using Microsoft.AspNetCore.Identity;
namespace SurveyBackend.Core.Models; namespace SurveyBackend.Core.Models;
public class User public class User : IdentityUser<int>
{ {
public int Id { get; set; }
public string FirstName { get; set; } public string FirstName { get; set; }
public string LastName { get; set; } public string LastName { get; set; }
public string Username { get; set; }
public string Email { get; set; }
public byte[] PasswordSalt { get; set; }
public byte[] PasswordHash { get; set; }
public ICollection<Group> Groups { get; set; } public ICollection<Group> Groups { get; set; }
} }

View file

@ -6,4 +6,9 @@
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
</PropertyGroup> </PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Identity" Version="2.3.1" />
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="8.0.14" />
</ItemGroup>
</Project> </Project>

View file

@ -1,11 +1,12 @@
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using SurveyBackend.Core.Models; using SurveyBackend.Core.Models;
namespace SurveyBackend.Infrastructure.Data; namespace SurveyBackend.Infrastructure.Data;
public class DataContext : DbContext public class DataContext : IdentityDbContext<User, IdentityRole<int>, int>
{ {
public DbSet<User> Users { get; set; }
public DbSet<Group> Groups { get; set; } public DbSet<Group> Groups { get; set; }
public DataContext(DbContextOptions<DataContext> options) : base(options) public DataContext(DbContextOptions<DataContext> options) : base(options)