Add project files.
This commit is contained in:
83
GreadyPoang.DataLayer/DataClasses/ParticipantRepository.cs
Normal file
83
GreadyPoang.DataLayer/DataClasses/ParticipantRepository.cs
Normal file
@ -0,0 +1,83 @@
|
||||
using Common.Library;
|
||||
using GreadyPoang.EntityLayer;
|
||||
using System.Collections.ObjectModel;
|
||||
|
||||
namespace GreadyPoang.DataLayer;
|
||||
|
||||
public class ParticipantRepository : IRepository<Participant>
|
||||
{
|
||||
|
||||
private ObservableCollection<Participant> lager;
|
||||
|
||||
public ParticipantRepository()
|
||||
{
|
||||
if (lager == null || lager.Count == 0)
|
||||
{
|
||||
lager = new ObservableCollection<Participant>();
|
||||
|
||||
lager.Add(new Participant
|
||||
{
|
||||
ParticipantId = 1,
|
||||
FirstName = @"Kalle",
|
||||
LastName = @"Persson",
|
||||
Email = @"kalle@person.com",
|
||||
});
|
||||
lager.Add(new Participant
|
||||
{
|
||||
ParticipantId = 2,
|
||||
FirstName = @"Olle",
|
||||
LastName = @"Goop",
|
||||
Email = @"olle@goop.com",
|
||||
});
|
||||
lager.Add(new Participant
|
||||
{
|
||||
ParticipantId = 3,
|
||||
FirstName = @"Nisse",
|
||||
LastName = @"Pärlemo",
|
||||
Email = @"nisse@parlemo.com"
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
#region Get Method
|
||||
public ObservableCollection<Participant> Get()
|
||||
{
|
||||
// This method should return a collection of Participant objects.
|
||||
// For now, returning an empty collection.
|
||||
return lager;
|
||||
}
|
||||
|
||||
public Participant? Get(int id)
|
||||
{
|
||||
return Get().Where(row => row.ParticipantId == id).FirstOrDefault();
|
||||
}
|
||||
#endregion
|
||||
|
||||
public bool Save(Participant entity)
|
||||
{
|
||||
if (entity.ParticipantId == 0)
|
||||
{
|
||||
// New entity
|
||||
var maxId = lager.Max(p => p.ParticipantId);
|
||||
entity.ParticipantId = maxId + 1;
|
||||
lager.Add(entity);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Existing entity
|
||||
var existing = Get(entity.ParticipantId);
|
||||
if (existing != null)
|
||||
{
|
||||
existing.FirstName = entity.FirstName;
|
||||
existing.LastName = entity.LastName;
|
||||
existing.Email = entity.Email;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false; // Entity not found
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
19
GreadyPoang.DataLayer/GreadyPoang.DataLayer.csproj
Normal file
19
GreadyPoang.DataLayer/GreadyPoang.DataLayer.csproj
Normal file
@ -0,0 +1,19 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net9.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="sqlite-net-pcl" Version="1.9.172" />
|
||||
<PackageReference Include="SQLitePCLRaw.bundle_green" Version="2.1.11" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Common.Library\Common.Library.csproj" />
|
||||
<ProjectReference Include="..\GreadyPoang.EntityLayer\GreadyPoang.EntityLayer.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
Reference in New Issue
Block a user