diff --git a/Timely/Components/TimeRecord.razor b/Timely/Components/TimeRecord.razor
index aa84228..e1e5fbc 100644
--- a/Timely/Components/TimeRecord.razor
+++ b/Timely/Components/TimeRecord.razor
@@ -1,6 +1,4 @@
@using Timely.Models
-@using Humanizer
-@using Microsoft.EntityFrameworkCore
@using Timely.Services.Data
@@ -30,6 +28,7 @@
@inject IDialogService DialogService
+@inject ShiftManager ShiftManager
@code {
@@ -43,10 +42,8 @@
{
return;
}
-
- await using var db = new AppDbContext();
- await db.Shifts.Where(shift => shift.Id == Shift.Id).ExecuteDeleteAsync();
- await db.SaveToCacheAsync();
+
+ await ShiftManager.RemoveShift(Shift.Id);
}
}
\ No newline at end of file
diff --git a/Timely/Program.cs b/Timely/Program.cs
index 37476d6..f0d2311 100644
--- a/Timely/Program.cs
+++ b/Timely/Program.cs
@@ -1,4 +1,3 @@
-using BlazorDB;
using Blazored.LocalStorage;
using Microsoft.AspNetCore.Components.Web;
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
@@ -22,6 +21,4 @@
var app = builder.Build();
-await app.Services.ConfigureBlazorDBAsync();
-
await app.RunAsync();
diff --git a/Timely/Services/Data/AppDbContext.cs b/Timely/Services/Data/AppDbContext.cs
deleted file mode 100644
index f9ee89e..0000000
--- a/Timely/Services/Data/AppDbContext.cs
+++ /dev/null
@@ -1,10 +0,0 @@
-using BlazorDB;
-using Microsoft.EntityFrameworkCore;
-using Timely.Models;
-
-namespace Timely.Services.Data;
-
-public class AppDbContext : BlazorDBContext
-{
- public DbSet Shifts { get; set; }
-}
\ No newline at end of file
diff --git a/Timely/Services/Data/ShiftManager.cs b/Timely/Services/Data/ShiftManager.cs
index 0a26827..be1eff4 100644
--- a/Timely/Services/Data/ShiftManager.cs
+++ b/Timely/Services/Data/ShiftManager.cs
@@ -31,6 +31,11 @@ public async Task AddTimeRecord(Shift shift)
await GetData();
_shifts ??= new();
+
+ var lastEntry = _shifts.OrderBy(shift => shift.Id).FirstOrDefault();
+ var id = lastEntry is null ? 0 : lastEntry.Id + 1;
+ shift.Id = id;
+
_shifts.Add(shift);
await SaveData();
@@ -59,8 +64,11 @@ public async Task StartShift()
{
if (_activeShift is not null) return;
+ var lastEntry = _shifts.OrderBy(shift => shift.Id).FirstOrDefault();
+ var id = lastEntry is null ? 0 : lastEntry.Id + 1;
var shift = new Shift()
{
+ Id = id,
Date = DateTime.Today,
ShiftStart = DateTime.Now.TimeOfDay,
Active = true
@@ -87,4 +95,12 @@ public async Task EndShift()
await SaveData();
}
+
+ public async Task RemoveShift(int id)
+ {
+ var toRemove = _shifts?.FirstOrDefault(shift => shift.Id == id);
+ if (toRemove is null) return;
+ _shifts?.Remove(toRemove);
+ await SaveData();
+ }
}
\ No newline at end of file