public async Task <IHttpActionResult> PutParticipant(Guid id, ParticipantAdminDto participantDto)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != participantDto.participantId)
            {
                return(BadRequest());
            }

            Participant participant = await db.Participants.FindAsync(participantDto.participantId);

            if (participant == null)
            {
                return(BadRequest());
            }

            participant.FirstName = participantDto.firstName;
            participant.LastName  = participantDto.lastName;
            participant.Dob       = participantDto.dob;
            participant.Gender    = participantDto.gender;

            db.SaveChanges();

            return(StatusCode(HttpStatusCode.NoContent));
        }
        public async Task <IHttpActionResult> DeleteDeviceActivation(Guid participantId, Guid deviceId)
        {
            Participant participant = await db.Participants.FindAsync(participantId);

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

            if (deviceId == Devices.Nest.DeviceId)
            {
                if (participant.NestAuthCode == null)
                {
                    return(BadRequest());
                }
                else
                {
                    participant.NestAuthCode   = null;
                    participant.NestAuthorized = false;
                    db.SaveChanges();
                    return(StatusCode(HttpStatusCode.NoContent));
                }
            }

            return(BadRequest());
        }
Esempio n. 3
0
        protected void Page_Load(object sender, EventArgs e)
        {
            string authCode      = Request.QueryString["code"];
            string participantId = Request.QueryString["state"];

            if (authCode == null || participantId == null)
            {
                throw new Exception("Invalid parameters");
            }

            string token = HAMS.Devices.Nest.GetToken(authCode);

            if (token == null)
            {
                throw new Exception("Invalid auth code");
            }

            Guid participantIdAsGuid;

            try
            {
                participantIdAsGuid = Guid.Parse(participantId);
            }
            catch (FormatException ex)
            {
                throw new Exception("Invalid parameters");
            }

            using (var db = new HAMSContext())
            {
                Participant participant = db.Participants.Find(participantIdAsGuid);
                if (participant == null)
                {
                    throw new Exception("Can't find participant: " + participantId);
                }
                participant.NestAuthorized = true;
                participant.NestAuthCode   = token;
                db.SaveChanges();
            }
        }
Esempio n. 4
0
        public static void CheckForValidatedConnections()
        {
            Collection <ValidatedPatientConnection> connectionList = Connections.GetValidatedConnectionsInPastDays(0);

            using (var db = new HAMSContext())
            {
                try
                {
                    // reset connections
                    foreach (Participant participant in db.Participants)
                    {
                        participant.Activated  = false;
                        participant.HVPersonId = null;
                        participant.HVRecordId = null;
                    }

                    // add validated connections
                    foreach (ValidatedPatientConnection connection in connectionList)
                    {
                        Guid        participantId = Guid.Parse(connection.ApplicationPatientId);
                        Participant participant   = db.Participants.Find(participantId);
                        if (participant == null || participant.Activated)
                        {
                            continue;
                        }
                        participant.Activated  = true;
                        participant.HVPersonId = connection.PersonId;
                        participant.HVRecordId = connection.RecordId;
                        db.SaveChanges();
                    }
                }
                catch (Exception ex)
                {
                    throw new Exception("ERROR: Unable to update Participants information: " + ex.Message.ToString(), ex);
                }
            }
        }