using Common.Library; using GreadyPoang.EntityLayer; using System.Collections.ObjectModel; namespace GreadyPoang.DataLayer; public class ParticipantRepository : IRepository { private ObservableCollection lager; public ParticipantRepository() { if (lager == null || lager.Count == 0) { lager = new ObservableCollection(); 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 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; } }