public Client getClient(int? id) { var c = dc.Clients.Include("Banks").FirstOrDefault(i => i.Id == id); if (c != null) { Client vc = new Client(); vc.Id = c.Id; vc.FirstName = c.FirstName; vc.LastName = c.LastName; vc.AccountNumber = c.AccountNumber; var lbs = new List<Bank>(); foreach (var item in c.Banks) { Bank b = new Bank(); b.Id = item.Id; b.Name = item.Name; b.Code = item.Code; lbs.Add(b); } vc.Banks = lbs; return vc; } return null; }
public List<Client> getListOfClients() { var cs = dc.Clients.OrderBy(n => n.Id); List<Client> lcs = new List<Client>(); foreach (var item in cs) { Client cn = new Client(); cn.Id = item.Id; cn.FirstName = item.FirstName; cn.LastName = item.LastName; cn.AccountNumber = item.AccountNumber; lcs.Add(cn); } return lcs; }
public Client createClient(ClientCreateForHttpPost cp) { var c = new Client(); c.Id = dc.Clients.Max(n => n.Id) + 1; c.FirstName = cp.FirstName; c.LastName = cp.LastName; c.AccountNumber = cp.AccountNumber; c.Banks = new List<Bank>(); foreach (var item in cp.BankIds) { Bank b = dc.Banks.FirstOrDefault(bk => bk.Id == item); if (b != null) c.Banks.Add(b); } dc.Clients.Add(c); dc.SaveChanges(); return getClient(c.Id); }