using Common.Library; using GreadyPoang.EntityLayer; using System.Collections.ObjectModel; namespace GreadyPoang.DataLayer; public class ParticipantRepository : IRepository { private readonly LocalDbService _dbService; private ObservableCollection lager; public ParticipantRepository(LocalDbService dbService) { if (lager == null || lager.Count == 0) { lager = new ObservableCollection(); } _dbService = dbService; } #region Get Method public async Task> Get() { // This method should return a collection of Participant objects. // For now, returning an empty collection. List result = await _dbService.GetParticipantsAsync(); if (result != null) { foreach (var participant in result) { if (!lager.Any(p => p.ParticipantId == participant.ParticipantId)) { lager.Add(participant); } } } return lager; } public Participant? Get(int id) { Participant? participant = null; // Initialize the variable to avoid CS0165 _dbService.GetParticipantAsync(id).ContinueWith(task => { if (task.Exception == null) { participant = task.Result; if (participant != null) { System.Diagnostics.Debug.WriteLine($"Fetched Participant by ID: {participant.ParticipantId}, {participant.FirstName}, {participant.LastName}, {participant.Email}"); } else { System.Diagnostics.Debug.WriteLine($"No Participant found with ID: {id}"); } } else { // Handle exceptions as needed System.Diagnostics.Debug.WriteLine($"Error fetching participant by ID: {task.Exception.Message}"); } }).Wait(); return participant; } #endregion public bool Save(Participant entity) { var output = false; try { _dbService.SaveParticipantAsync(entity).Wait(); lager.Add(entity); output = true; } catch (Exception ex) { System.Diagnostics.Debug.WriteLine($"Error saving participants: {ex.Message}"); } return output; } }