using System.Collections.Generic;
using System.Data.SqlClient;
using System.Threading.Tasks;
public class PersonController
public string Get(string name)
var dataProvider = new PersonDataProvider();
return ConvertToJson(dataProvider.GetPerson(name));
public string GetAllWithManager()
var dataProvider = new PersonDataProvider();
var persons = dataProvider.GetAllPersonAsyn().Result;
foreach (var item in persons)
item.Manager = dataProvider.GetManager(item.ManagerId).Result;
return ConvertToJson(persons);
private string ConvertToJson(object obj)
throw new NotImplementedException();
public class PersonDataProvider
SqlConnection conn = new SqlConnection();
public Person GetPerson(string name)
SqlCommand sc = new SqlCommand($"Select * from Person where name = '{name}'");
var reader = sc.ExecuteReader();
public async Task<Person> GetPersonAsyn(string name)
SqlCommand sc = new SqlCommand($"Select * from Person where name = '{name}'");
var reader = await sc.ExecuteReaderAsync();
public async Task<List<Person>> GetAllPersonAsyn()
SqlCommand sc = new SqlCommand($"Select * from Person");
var reader = await sc.ExecuteReaderAsync();
return new List<Person>();
public async Task<Manager> GetManager(int id)
SqlCommand sc = new SqlCommand($"Select * from Manager where Id = {id}");
var reader = await sc.ExecuteReaderAsync();
public int Id { get; set; }
public string Name { get; set; }
public int ManagerId { get; set; }
public Manager Manager { get; set; }
public string Name { get; set; }