Files
GreadyPoang/GreadyPoang.DataLayer/DataClasses/ParticipantRepository.cs
2025-08-28 11:32:25 +02:00

84 lines
2.1 KiB
C#

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;
}
}