/// <summary> /// GetVirtualMachinesByUser /// </summary> /// <param name="_currentUser"></param> /// <returns></returns> public JsonResult GetVirtualMachinesByUser(ClaimsPrincipal _currentUser) { List <VM> vMashines = new List <VM>(); using (var context = new CADContext()) { try { User currentUser = context.Users .Include(u => u.Dashboard) .ThenInclude(d => d.DashboardApplications) .FirstOrDefault(u => u.UserName == _currentUser.Identity.Name); if (currentUser?.Dashboard == null) { return(new JsonResult(new { data = "" })); } var dashboard = context.Dashboards.Include(d => d.DashboardApplications).FirstOrDefault(d => d.DashboardId == currentUser.Dashboard.DashboardId); if (currentUser.Dashboard.DashboardId != 0) { vMashines = VirtualMashinesList.GetVMs(currentUser.Dashboard.DashboardId); } } catch (Exception ex) { Log log = new Log(); log.name = ex.ToString(); log.timestamp = DateTime.UtcNow; context.Logs.Add(log); context.SaveChanges(); } } return(new JsonResult(new { data = vMashines })); }
/// <summary> /// GetVirtualMachinesByAccessCode /// </summary> /// <param name="_accessCode"></param> /// <returns></returns> public List <VM> GetVirtualMachinesByAccessCode(string _accessCode) { Dashboard dashboard; List <VM> vMashines = new List <VM>(); using (var context = new CADContext()) { try { dashboard = context.Dashboards.Include(d => d.DashboardApplications).FirstOrDefault(d => d.DashboardAnonAccessCode == _accessCode); vMashines = VirtualMashinesList.GetVMs(dashboard.DashboardId); } catch (Exception ex) { Log log = new Log(); log.name = ex.ToString(); log.timestamp = DateTime.UtcNow; context.Logs.Add(log); context.SaveChanges(); } } return(vMashines); }