|
|
@ -0,0 +1,135 @@
|
|
|
|
|
|
|
|
using System.ComponentModel;
|
|
|
|
|
|
|
|
using Dto;
|
|
|
|
|
|
|
|
using Share;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace StubbedDtoLib;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public class AthleteStubDto : IAthleteService
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
private static List<AthleteDto> AthleteList = new List<AthleteDto>()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
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<IEnumerable<AthleteDto>> GetAllAthletesAsync()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return AthleteList;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public async Task<IEnumerable<AthleteDto>> GetSomeAthletesAsync(int index, int count)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return AthleteList.Skip(count*index).Take(count);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public async Task<AthleteDto?> GetAthleteByIdAsync(int id) => AthleteList.Find(a => a.IdAthlete == id);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public async Task<IEnumerable<AthleteDto>> 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<IEnumerable<AthleteDto>> 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<IEnumerable<AthleteDto>> 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<IEnumerable<AthleteDto>> 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<IEnumerable<AthleteDto>> 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<IEnumerable<AthleteDto>> GetAthletesByLenghtAsync(double lenght, int index, int count)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return AthleteList.FindAll(a => a.Lenght == lenght).Skip(index*count).Take(count);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public async Task<IEnumerable<AthleteDto>> GetAthletesByWeightAsync(float weight, int index, int count)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return AthleteList.FindAll(a => a.Weight == weight).Skip(index*count).Take(count);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public async Task<IEnumerable<AthleteDto>> GetAthletesByDateOfBirthAsync(DateTime dateOfBirth, int index, int count)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return AthleteList.FindAll(a => a.DateOfBirth == dateOfBirth).Skip(index*count).Take(count);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public async Task<IEnumerable<AthleteDto>> GetAthletesByIsCoachAsync(bool isCoach, int index, int count)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return AthleteList.FindAll(a => a.IsCoach == isCoach).Skip(index*count).Take(count);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public async Task<AthleteDto> 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<AthleteDto?> 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<bool> DeleteAthleteAsync(int id)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
var theId = AthleteList.FindIndex(a => a.IdAthlete == id);
|
|
|
|
|
|
|
|
if (theId >= 0)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
AthleteList.RemoveAt(theId);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
} else
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|