Skip to content

Commit

Permalink
⚰️ Remove references from BlazorDb
Browse files Browse the repository at this point in the history
  • Loading branch information
russkyc committed May 28, 2024
1 parent 2fd40b6 commit 83aaba8
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 19 deletions.
9 changes: 3 additions & 6 deletions Timely/Components/TimeRecord.razor
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
@using Timely.Models
@using Humanizer
@using Microsoft.EntityFrameworkCore
@using Timely.Services.Data
<MudPaper Elevation="0" Class="rounded-lg bg-[#f3f2fc] p-3">
<MudStack Row="true">
Expand Down Expand Up @@ -30,6 +28,7 @@
</MudPaper>

@inject IDialogService DialogService
@inject ShiftManager ShiftManager

@code {

Expand All @@ -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);
}

}
3 changes: 0 additions & 3 deletions Timely/Program.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using BlazorDB;
using Blazored.LocalStorage;
using Microsoft.AspNetCore.Components.Web;
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
Expand All @@ -22,6 +21,4 @@

var app = builder.Build();

await app.Services.ConfigureBlazorDBAsync<AppDbContext>();

await app.RunAsync();
10 changes: 0 additions & 10 deletions Timely/Services/Data/AppDbContext.cs

This file was deleted.

16 changes: 16 additions & 0 deletions Timely/Services/Data/ShiftManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -59,8 +64,11 @@ public async Task StartShift()
{
if (_activeShift is not null) return;

var lastEntry = _shifts.OrderBy(shift => shift.Id).FirstOrDefault();

Check warning on line 67 in Timely/Services/Data/ShiftManager.cs

View workflow job for this annotation

GitHub Actions / deploy-to-github-pages

Possible null reference argument for parameter 'source' in 'IOrderedEnumerable<Shift> Enumerable.OrderBy<Shift, int>(IEnumerable<Shift> source, Func<Shift, int> keySelector)'.
var id = lastEntry is null ? 0 : lastEntry.Id + 1;
var shift = new Shift()
{
Id = id,
Date = DateTime.Today,
ShiftStart = DateTime.Now.TimeOfDay,
Active = true
Expand All @@ -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();
}
}

0 comments on commit 83aaba8

Please sign in to comment.