public FindIdentitiesResponseObj FindIdentities()
        {
            log.Info("Incoming request to " + GetCurrentMethod());

            //_logEventService.Init(Common.DataAccess.Entities.EventDataType.Other);
            _logEventService.LogInfo(EventNumber.SPIS_consumeService, EventDataType.None, null, null);

            try
            {
                var responsObjects = _sscService.FindIdentities();

                _logEventService.LogSuccess(EventNumber.SPIS_consumeService, EventDataType.Other, null,
                                            JsonConvert.SerializeObject(responsObjects, Formatting.Indented));

                return(responsObjects);
            }
            catch (HttpResponseException ex)
            {
                _logEventService.LogError(EventNumber.SPIS_consumeService, EventType.Error_internal,
                                          null, ex.Response.ToString());

                throw;
            }
            catch (Exception ex)
            {
                log.Error(ex.Message, ex);

                string msg = "SPIS internal server error. " + ex.Message;
                _logEventService.LogError(EventNumber.SPIS_consumeService, EventType.Error_internal,
                                          null, ex.Message);

                throw CreateHttpResponseException(HttpStatusCode.InternalServerError, msg);
            }
        }
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public Identity GetCallerIdentity()
        {
            // Get id for caller
            var identity = Get(x => x.UID == InstanceContext.CallerOrgId).FirstOrDefault();

            if (identity == null)
            {
                var fiResponse = _sscService.FindIdentities();

                if (fiResponse.StatusCode == 200 &&
                    fiResponse != null && fiResponse.Organizations != null)
                {
                    var orgs = fiResponse.Organizations;
                    var org  = orgs.FirstOrDefault(x => x.Mrn == InstanceContext.CallerOrgId);
                    if (org == null)
                    {
                        throw new Exception("Unable to lookup identity in ID registry");
                    }

                    identity = new Identity
                    {
                        UID  = org.Mrn,
                        Name = org.Name
                    };
                    Insert(identity);
                }
                else
                {
                    throw new Exception("Unable to lookup identity in ID registry");
                }
            }

            return(identity);
        }
        public FindIdentitiesResponseObj FindIdentities()
        {
            log.Info("Incoming request to " + GetCurrentMethod());

            _logEventService.LogInfo(EventNumber.VIS_consumeService, EventDataType.None, null, null);

            try
            {
                var responsObjects = _sscService.FindIdentities();

                _logEventService.LogSuccess(EventNumber.VIS_consumeService, EventDataType.Other, null, JsonConvert.SerializeObject(responsObjects, Formatting.Indented));

                //set last interaction time
                var conInfo = _connectionInformationService.Get().FirstOrDefault();
                if (conInfo == null)
                {
                    _connectionInformationService.Insert(new ConnectionInformation {
                        LastInteraction = DateTime.UtcNow
                    });
                }
                else
                {
                    conInfo.LastInteraction = DateTime.UtcNow;
                    _connectionInformationService.Update(conInfo);
                }
                _context.SaveChanges();

                return(responsObjects);
            }
            catch (HttpResponseException ex)
            {
                _logEventService.LogError(EventNumber.VIS_consumeService, EventType.Error_internal,
                                          null, JsonConvert.SerializeObject(ex.Response, Formatting.Indented));

                throw;
            }
            catch (Exception ex)
            {
                log.Error(ex.Message, ex);

                string msg = "VIS internal server error. " + ex.Message;

                _logEventService.LogError(EventNumber.VIS_consumeService, EventType.Error_internal,
                                          null, ex.Message);

                throw CreateHttpResponseException(HttpStatusCode.InternalServerError, msg);
            }
        }