-
-
Save Ershad95/7dd2920e5312263b375356734078b473 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[ApiController] | |
[Route("[controller]")] | |
public class CustomerController : ControllerBase | |
{ | |
private readonly IDictionary<int, Customer> _customers; | |
private void FillCustomerFromMemory(int countOfCustomer) | |
{ | |
for (int CustomerId = 1; CustomerId <= countOfCustomer; CustomerId++) | |
{ | |
_customers.Add(key: CustomerId, new Customer($"name_{CustomerId}", CustomerId)); | |
} | |
} | |
public CustomerController() | |
{ | |
_customers = new Dictionary<int, Customer>(); | |
FillCustomerFromMemory(countOfCustomer : 100); | |
} | |
[HttpGet] | |
public async Task<IEnumerable<Customer>> Get() | |
{ | |
var output = new List<Customer>(); | |
while (_customers.Any(_ => _.Key % 10 == 0)) | |
{ | |
var customer = _customers.First(_ => _.Key % 10 == 0); | |
output.Add(new Customer(customer.Value.Name, customer.Key)); | |
await Task.Delay(500); | |
_customers.Remove(customer); | |
} | |
return output; | |
} | |
public class Customer | |
{ | |
public int Id { get; private set; } | |
public string Name { get; private set; } | |
public Customer(string name, int id) | |
{ | |
Name = name; | |
Id = id; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment