Details ausgearbeitet
Linked colors to options menu Options extension Aussehen aufgebohrt: - erlaubt text von status zu ändern, - bessere beschriftung von Farben desing änderung und bedienung - heute status felder anklickbar, - Farbpalette verdunkelt und kontrast reduziert - Kalender Tage anklickbar gemacht - Optionen überarbeitet
This commit is contained in:
@@ -0,0 +1,135 @@
|
||||
using cfs_tracker.Models;
|
||||
|
||||
namespace cfs_tracker.Data;
|
||||
|
||||
public class ActivityRepository
|
||||
{
|
||||
private readonly AppDatabase _database;
|
||||
|
||||
public ActivityRepository(AppDatabase database)
|
||||
{
|
||||
_database = database;
|
||||
}
|
||||
|
||||
public async Task<List<ActivityItem>> GetAllAsync()
|
||||
{
|
||||
await _database.InitAsync();
|
||||
|
||||
return await _database.Connection.Table<ActivityItem>()
|
||||
.OrderBy(x => x.SortOrder)
|
||||
.ThenBy(x => x.Name)
|
||||
.ToListAsync();
|
||||
}
|
||||
|
||||
public async Task<List<ActivityItem>> GetActiveAsync()
|
||||
{
|
||||
await _database.InitAsync();
|
||||
|
||||
return await _database.Connection.Table<ActivityItem>()
|
||||
.Where(x => x.IsActive)
|
||||
.OrderBy(x => x.SortOrder)
|
||||
.ThenBy(x => x.Name)
|
||||
.ToListAsync();
|
||||
}
|
||||
|
||||
public async Task<Dictionary<int, string>> GetNameMapAsync()
|
||||
{
|
||||
var all = await GetAllAsync();
|
||||
return all.ToDictionary(x => x.Id, x => x.Name);
|
||||
}
|
||||
|
||||
public async Task EnsureDefaultsAsync()
|
||||
{
|
||||
await _database.InitAsync();
|
||||
|
||||
if ((await _database.Connection.Table<ActivityItem>().CountAsync()) > 0)
|
||||
return;
|
||||
|
||||
var defaults = new List<ActivityItem>
|
||||
{
|
||||
new() { Name = "Lesen", SortOrder = 0, IsActive = true },
|
||||
new() { Name = "Sport", SortOrder = 1, IsActive = true },
|
||||
new() { Name = "Haushalt", SortOrder = 2, IsActive = true },
|
||||
new() { Name = "Einkaufen", SortOrder = 3, IsActive = true },
|
||||
new() { Name = "Ausgehen", SortOrder = 4, IsActive = true },
|
||||
new() { Name = "Verwaltung", SortOrder = 5, IsActive = true },
|
||||
new() { Name = "Gespräch", SortOrder = 6, IsActive = true },
|
||||
new() { Name = "Spazieren gehen", SortOrder = 7, IsActive = true },
|
||||
new() { Name = "Fernsehen", SortOrder = 8, IsActive = true },
|
||||
new() { Name = "Ruhen / Liegen", SortOrder = 9, IsActive = true }
|
||||
};
|
||||
|
||||
foreach (var item in defaults)
|
||||
await _database.Connection.InsertAsync(item);
|
||||
}
|
||||
|
||||
public async Task AddAsync(string name)
|
||||
{
|
||||
await _database.InitAsync();
|
||||
|
||||
var maxSort = 0;
|
||||
var all = await _database.Connection.Table<ActivityItem>().ToListAsync();
|
||||
if (all.Count > 0)
|
||||
maxSort = all.Max(x => x.SortOrder) + 1;
|
||||
|
||||
await _database.Connection.InsertAsync(new ActivityItem
|
||||
{
|
||||
Name = name.Trim(),
|
||||
SortOrder = maxSort,
|
||||
IsActive = true
|
||||
});
|
||||
}
|
||||
|
||||
public async Task RenameAsync(int id, string newName)
|
||||
{
|
||||
await _database.InitAsync();
|
||||
|
||||
var item = await _database.Connection.Table<ActivityItem>()
|
||||
.FirstOrDefaultAsync(x => x.Id == id);
|
||||
|
||||
if (item is null)
|
||||
return;
|
||||
|
||||
item.Name = newName.Trim();
|
||||
await _database.Connection.UpdateAsync(item);
|
||||
}
|
||||
|
||||
public async Task SetActiveAsync(int id, bool isActive)
|
||||
{
|
||||
await _database.InitAsync();
|
||||
|
||||
var item = await _database.Connection.Table<ActivityItem>()
|
||||
.FirstOrDefaultAsync(x => x.Id == id);
|
||||
|
||||
if (item is null)
|
||||
return;
|
||||
|
||||
item.IsActive = isActive;
|
||||
await _database.Connection.UpdateAsync(item);
|
||||
}
|
||||
|
||||
public async Task<bool> HasUsageAsync(int activityId)
|
||||
{
|
||||
await _database.InitAsync();
|
||||
|
||||
var count = await _database.Connection.Table<HealthEntry>()
|
||||
.Where(x => x.ActivityId == activityId)
|
||||
.CountAsync();
|
||||
|
||||
return count > 0;
|
||||
}
|
||||
|
||||
public async Task DeleteIfUnusedAsync(int activityId)
|
||||
{
|
||||
await _database.InitAsync();
|
||||
|
||||
if (await HasUsageAsync(activityId))
|
||||
return;
|
||||
|
||||
var item = await _database.Connection.Table<ActivityItem>()
|
||||
.FirstOrDefaultAsync(x => x.Id == activityId);
|
||||
|
||||
if (item is not null)
|
||||
await _database.Connection.DeleteAsync(item);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user