| | | 1 | | using System; |
| | | 2 | | using System.Collections.Generic; |
| | | 3 | | using System.Linq; |
| | | 4 | | using System.Threading.Tasks; |
| | | 5 | | using Server.Data.Entities; |
| | | 6 | | |
| | | 7 | | namespace Server.Data; |
| | | 8 | | |
| | | 9 | | public class UsersRepository : IUsersRepository |
| | | 10 | | { |
| | 6 | 11 | | private readonly string[] _users = { |
| | 6 | 12 | | "Anne Ware", |
| | 6 | 13 | | "Beverly Montgomery", |
| | 6 | 14 | | "Chanda Gomez", |
| | 6 | 15 | | "Clinton Wood", |
| | 6 | 16 | | "Dawn English", |
| | 6 | 17 | | "Dean David", |
| | 6 | 18 | | "Ezra Boone", |
| | 6 | 19 | | "Gisela Little", |
| | 6 | 20 | | "Ila Santana", |
| | 6 | 21 | | "Joseph Kim", |
| | 6 | 22 | | "Laurel Gardner", |
| | 6 | 23 | | "Lois Smith", |
| | 6 | 24 | | "Maya Klein", |
| | 6 | 25 | | "Quynn West", |
| | 6 | 26 | | "Rowan Aguilar", |
| | 6 | 27 | | "Walter Parrish", |
| | 6 | 28 | | "Winter Bryant", |
| | 6 | 29 | | "Winter Mccray", |
| | 6 | 30 | | "Yoshi Lambert" |
| | 6 | 31 | | }; |
| | | 32 | | |
| | | 33 | | private readonly Dictionary<string, User> _store; |
| | | 34 | | |
| | 6 | 35 | | public UsersRepository() |
| | 234 | 36 | | => _store = _users.ToDictionary(x => x, x => new User { Name = x }); |
| | | 37 | | |
| | | 38 | | public Task<User?> GetUser(string name) |
| | | 39 | | { |
| | 30 | 40 | | if (_store.TryGetValue(name, out var user)) |
| | 24 | 41 | | return Task.FromResult<User?>(user); |
| | | 42 | | |
| | 6 | 43 | | return Task.FromResult<User?>(null); |
| | | 44 | | } |
| | | 45 | | |
| | | 46 | | Task<IEnumerable<User>> IUsersRepository.GetUsers(string? name) |
| | | 47 | | { |
| | 12 | 48 | | var users = _store.Values.AsEnumerable(); |
| | | 49 | | |
| | 12 | 50 | | if (!string.IsNullOrWhiteSpace(name)) |
| | | 51 | | { |
| | 126 | 52 | | users = users.Where(x => x.Name.Contains(name, StringComparison.OrdinalIgnoreCase)); |
| | | 53 | | } |
| | | 54 | | |
| | 12 | 55 | | return Task.FromResult(users); |
| | | 56 | | } |
| | | 57 | | |
| | | 58 | | public Task<User> CreateUser(User user) |
| | | 59 | | { |
| | 6 | 60 | | _store[user.Name] = user; |
| | 6 | 61 | | return Task.FromResult(user); |
| | | 62 | | } |
| | | 63 | | } |