using System.ComponentModel; using Dto; using Share; namespace StubbedDtoLib; public class AthleteStubDto : IAthleteService { private static List AthleteList = new List() { new AthleteDto { IdAthlete = 1, Username = "Doe", LastName = "John", FirstName = "Doe", Email = "john.doe@example.com", Password = "password123", Sexe = "M", Lenght = 1.80, Weight = 75, DateOfBirth = new DateTime(), IsCoach = true }, new AthleteDto { IdAthlete = 2, Username = "Smith", LastName = "Jane", FirstName = "Smith", Email = "jane.smith@example.com", Password = "secure456", Sexe = "F", Lenght = 1.65, Weight = 60, DateOfBirth = new DateTime(), IsCoach = false }, new AthleteDto { IdAthlete = 3, Username = "Martin", LastName = "Paul", FirstName = "Martin", Email = "paul.martin@example.com", Password = "super789", Sexe = "M", Lenght = 1.75, Weight = 68, DateOfBirth = new DateTime(), IsCoach = true }, new AthleteDto { IdAthlete = 4, Username = "Brown", LastName = "Anna", FirstName = "Brown", Email = "anna.brown@example.com", Password = "test000", Sexe = "M", Lenght = 1.70, Weight = 58, DateOfBirth = new DateTime(), IsCoach = false }, new AthleteDto { IdAthlete = 5, Username = "Lee", LastName = "Bruce", FirstName = "Lee", Email = "bruce.lee@example.com", Password = "hello321", Sexe = "M", Lenght = 2.0, Weight = 90, DateOfBirth = new DateTime(), IsCoach = false } }; public async Task> GetAllAthletesAsync() { return AthleteList; } public async Task> GetSomeAthletesAsync(int index, int count) { return AthleteList.Skip(count*index).Take(count); } public async Task GetAthleteByIdAsync(int id) => AthleteList.Find(a => a.IdAthlete == id); public async Task> GetAthleteByUsernameAsync(string username, int index, int count) { return AthleteList.FindAll(a => a.Username.Contains(username, StringComparison.OrdinalIgnoreCase)).Skip(index*count).Take(count); } public async Task> GetAthletesByEmailAsync(string email, int index, int count) { return AthleteList.FindAll(a => a.Email.Contains(email, StringComparison.OrdinalIgnoreCase)).Skip(index*count).Take(count); } public async Task> GetAthletesByFirstNameAsync(string firstName, int index, int count) { return AthleteList.FindAll(a => a.FirstName.Contains(firstName, StringComparison.OrdinalIgnoreCase)).Skip(index*count).Take(count); } public async Task> GetAthletesByLastNameAsync(string lastName, int index, int count) { return AthleteList.FindAll(a => a.LastName.Contains(lastName, StringComparison.OrdinalIgnoreCase)).Skip(index*count).Take(count); } public async Task> GetAthletesBySexeAsync(string sexe, int index, int count) { return AthleteList.FindAll(a => a.Sexe.Contains(sexe, StringComparison.OrdinalIgnoreCase)).Skip(index*count).Take(count); } public async Task> GetAthletesByLenghtAsync(double lenght, int index, int count) { return AthleteList.FindAll(a => a.Lenght == lenght).Skip(index*count).Take(count); } public async Task> GetAthletesByWeightAsync(float weight, int index, int count) { return AthleteList.FindAll(a => a.Weight == weight).Skip(index*count).Take(count); } public async Task> GetAthletesByDateOfBirthAsync(DateTime dateOfBirth, int index, int count) { return AthleteList.FindAll(a => a.DateOfBirth == dateOfBirth).Skip(index*count).Take(count); } public async Task> GetAthletesByIsCoachAsync(bool isCoach, int index, int count) { return AthleteList.FindAll(a => a.IsCoach == isCoach).Skip(index*count).Take(count); } public async Task AddAthleteAsync(AthleteDto athlete) { var newAthlete = new AthleteDto() { IdAthlete = AthleteList.Max(a => a.IdAthlete) + 1, Username = athlete.Username, LastName = athlete.LastName, FirstName = athlete.FirstName, Email = athlete.Email, Password = athlete.Password, Sexe = athlete.Sexe, Lenght = athlete.Lenght, Weight = athlete.Weight, DateOfBirth = athlete.DateOfBirth, IsCoach = athlete.IsCoach }; AthleteList.Add(newAthlete); return newAthlete; } public async Task UpdateAthleteAsync(int id, AthleteDto athlete) { var theId = AthleteList.FindIndex(a => a.IdAthlete == id); if (theId >= 0) { var a = AthleteList[theId]; a.Username = athlete.Username; a.LastName = athlete.LastName; a.FirstName = athlete.FirstName; a.Email = athlete.Email; a.Password = athlete.Password; a.Sexe = athlete.Sexe; a.Lenght = athlete.Lenght; a.Weight = athlete.Weight; a.DateOfBirth = athlete.DateOfBirth; a.IsCoach = athlete.IsCoach; AthleteList[theId] = a; return a; } else { return null; } } public async Task DeleteAthleteAsync(int id) { var theId = AthleteList.FindIndex(a => a.IdAthlete == id); if (theId >= 0) { AthleteList.RemoveAt(theId); return true; } else { return false; } } }