Skip to content

Commit 5d5afe0

Browse files
committed
Added persistance for SkillTable
1 parent 20ea101 commit 5d5afe0

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

LinkDotNet.Blog.Web/RegistrationExtensions/SqlRegistrationExtensions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public static void UseSqlAsStorageProvider(this IServiceCollection services)
1212
{
1313
services.AssertNotAlreadyRegistered(typeof(IRepository<>));
1414

15-
services.AddScoped(s =>
15+
services.AddTransient(s =>
1616
{
1717
var configuration = s.GetService<AppConfiguration>() ?? throw new NullReferenceException(nameof(AppConfiguration));
1818
var connectionString = configuration.ConnectionString;
@@ -29,7 +29,7 @@ public static void UseSqliteAsStorageProvider(this IServiceCollection services)
2929
{
3030
services.AssertNotAlreadyRegistered(typeof(IRepository<>));
3131

32-
services.AddScoped(s =>
32+
services.AddTransient(s =>
3333
{
3434
var configuration = s.GetService<AppConfiguration>() ?? throw new NullReferenceException(nameof(AppConfiguration));
3535
var connectionString = configuration.ConnectionString;

LinkDotNet.Blog.Web/Shared/Skills/SkillTable.razor

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
@using LinkDotNet.Domain
2+
@using LinkDotNet.Infrastructure.Persistence
3+
@inject IRepository<Skill> repository
24
<div class="skill-table-container">
35
<div>
46
@if (IsAuthenticated)
@@ -59,25 +61,32 @@
5961

6062
private Skill currentDragItem;
6163

62-
private Task AddSkill(Skill skillToAdd)
64+
protected override async Task OnInitializedAsync()
65+
{
66+
skills = (await repository.GetAllAsync()).ToList();
67+
}
68+
69+
private async Task AddSkill(Skill skillToAdd)
6370
{
6471
skills.Add(skillToAdd);
65-
return Task.CompletedTask;
72+
await repository.StoreAsync(skillToAdd);
6673
}
6774

68-
private void DeleteSkill(Skill skill)
75+
private async Task DeleteSkill(Skill skill)
6976
{
7077
skills.Remove(skill);
78+
await repository.DeleteAsync(skill.Id);
7179
}
7280

73-
private void HandleDrop(ProficiencyLevel proficiencyLevel)
81+
private async Task HandleDrop(ProficiencyLevel proficiencyLevel)
7482
{
7583
if (currentDragItem == null || currentDragItem.ProficiencyLevel == proficiencyLevel)
7684
{
7785
return;
7886
}
7987

8088
currentDragItem.ProficiencyLevel = proficiencyLevel;
89+
await repository.StoreAsync(currentDragItem);
8190
currentDragItem = null;
8291
}
8392

0 commit comments

Comments
 (0)