public IActionResult RegisterLabAction(string labAction, int labProfileId, long labInstanceId, string globalLabInstanceId,
                                               string userId, string firstName, string lastName, string email)
        {
            var apiUrl = _Settings.APIURL;
            var apiKey = _Settings.APIKey;
            var client = new LabOnDemandApiClient(apiUrl, apiKey);

            // check whitelist!
            if (!_Settings.IPWhitelist.Contains(Request.HttpContext.Connection.RemoteIpAddress.ToString()))
            {
                return(NotFound());
            }

            // verify that LOD knows about this launch!
            var details = client.Details(labInstanceId);

            if (!(details.UserId == userId ||
                  (details.UserFirstName == firstName && details.UserLastName == lastName)) ||
                details.LabProfileId != labProfileId)
            {
                return(NotFound());
            }

            // if we get here, everything checks out, so add our record!
            var launch = new LabAction
            {
                FirstName            = details.UserFirstName,
                LastName             = details.UserLastName,
                State                = details.State,
                Status               = details.Status.ToString(),
                LabInstanceId        = labInstanceId,
                LabProfileId         = details.LabProfileId,
                LabProfileName       = details.LabProfileName,
                LabActionDescription = labAction
            };

            _context.Add(launch);
            _context.SaveChanges();

            return(Json(new { success = true }));
        }
        public IActionResult CancelLab(long labRecordId)
        {
            var launchRecord = _context.LabLaunch.FirstOrDefault(rec => rec.Id == labRecordId);

            if (launchRecord == null)
            {
                return(NotFound());
            }

            var apiUrl = _Settings.APIURL;
            var apiKey = _Settings.APIKey;
            var client = new LabOnDemandApiClient(apiUrl, apiKey);

            var labInstance = client.Details(launchRecord.LabInstanceId);

            if (labInstance.State != "Running")
            {
                return(BadRequest());
            }

            var response = client.Cancel(launchRecord.LabInstanceId, "Canceled from remote test site");

            if (response.Result == CancelResult.Success)
            {
                var launch = new LabAction
                {
                    FirstName            = labInstance.UserFirstName,
                    LastName             = labInstance.UserLastName,
                    State                = labInstance.State,
                    Status               = labInstance.Status.ToString(),
                    LabInstanceId        = labInstance.Id,
                    LabProfileId         = labInstance.LabProfileId,
                    LabProfileName       = labInstance.LabProfileName,
                    LabActionDescription = "Lab canceled from Demo Site"
                };
                _context.Add(launch);
                _context.SaveChanges();
            }

            return(RedirectToAction(nameof(Index)));
        }