public async Task <IActionResult> Index() { var clients = await _db.Clients.ToListAsync(); List <IndexClientGetModel.ClientApps> list = new List <IndexClientGetModel.ClientApps>(); foreach (var c in clients) { var apps = await _db.Licenses .Include(l => l.Client) .Include(l => l.ApplicationVersion) .ThenInclude(av => av.Application) .Where(l => l.Client.Id == c.Id) .ToListAsync(); var ca = new IndexClientGetModel.ClientApps() { Client = c, Licenses = apps }; list.Add(ca); } return(View(new IndexClientGetModel { Clients = list /*Clients = clients, AppsClient = apps*/ })); }
public async Task <IActionResult> Delete(int id) { var c = await _db.Clients.Where(cc => cc.Id == id).FirstOrDefaultAsync(); var clients = await _db.Clients.ToListAsync(); List <IndexClientGetModel.ClientApps> list = new List <IndexClientGetModel.ClientApps>(); foreach (var cc in clients) { var apps = await _db.Licenses .Include(l => l.Client) .Include(l => l.ApplicationVersion) .ThenInclude(av => av.Application) .Where(l => l.Client.Id == cc.Id) .ToListAsync(); var ca = new IndexClientGetModel.ClientApps() { Client = cc, Licenses = apps }; list.Add(ca); } if (c == null) { return(View("Index", new IndexClientGetModel { Clients = list, Error = 1 })); } var appsc = list.Where(cccc => cccc.Client == c).FirstOrDefault(); if (appsc.Licenses.Count > 0) { return(View("Index", new IndexClientGetModel { Clients = list, Error = 2 })); } _db.Addresses.Remove(c.Address); _db.Clients.Remove(c); await _db.SaveChangesAsync(); return(RedirectToAction("Index")); }