generated from admin/template
45 lines
1.5 KiB
C#
45 lines
1.5 KiB
C#
using PokedexApi.Models;
|
|
|
|
namespace PokedexApi.Storage;
|
|
|
|
public class PokemonStorage
|
|
{
|
|
private List<Pokemon> _pokemons = new List<Pokemon>
|
|
{
|
|
new Pokemon(1, "Pikachu", "Electric", 12),
|
|
new Pokemon(2, "Charmander", "Fire", 8),
|
|
new Pokemon(3, "Squirtle", "Water", 10)
|
|
};
|
|
|
|
private readonly object _lock = new object();
|
|
|
|
public void DoSomething()
|
|
{
|
|
lock (_lock)
|
|
{
|
|
// этот блок выполняет только один поток за раз
|
|
// остальные ждут, пока он выйдет
|
|
}
|
|
}
|
|
new Pokemon(1, "Pikachu", ...)
|
|
private readonly object _lock = new object();
|
|
|
|
// TODO 3: реализуй метод GetAll()
|
|
// TODO 4: реализуй метод GetById(int id)
|
|
// TODO 5: реализуй метод Filter(string? type, int? minLevel)
|
|
if (type != null && p.Type != type) continue;
|
|
if (minLevel != null && p.Level < minLevel) continue;
|
|
result.Add(p);
|
|
// TODO 6: реализуй метод SearchByName(string query)
|
|
// TODO 7: реализуй метод Add(PokemonInput input)
|
|
int newId = 1;
|
|
foreach (var p in _pokemons)
|
|
{
|
|
if (p.Id >= newId) newId = p.Id + 1;
|
|
}
|
|
new Pokemon(newId, input.Name, input.Type, input.Level)
|
|
|
|
// TODO 8: реализуй метод Update(int id, PokemonInput input)
|
|
// TODO 9: реализуй метод UpdateLevel(int id, int level)
|
|
// TODO 10: реализуй метод Delete(int id)
|
|
} |