Ejemplo n.º 1
0
        public DbStatus UnverifyResearcherDB(int resID)
        {
            Researcher researcher = _context.Researcher.FirstOrDefault(res => res.IdResearcher == resID);
            DbStatus   UnverifyResearcherStatus = new DbStatus();

            if (researcher != null)
            {
                if (researcher.Isverified == true)
                {
                    //Unverify researcher
                    researcher.Isverified = false;
                    _context.Update(researcher);
                    _context.SaveChanges();
                    UnverifyResearcherStatus.success = true;
                }
                else
                {
                    //Researcher was not verified
                    UnverifyResearcherStatus.success      = false;
                    UnverifyResearcherStatus.errormessage = "Researcher is not verified";
                }
            }
            else
            {
                //Researcher does not exists
                UnverifyResearcherStatus.success      = false;
                UnverifyResearcherStatus.errormessage = "Researcher with this ID does not exists";
            }
            return(UnverifyResearcherStatus);
        }
        public DbStatus AddParticipantToStudyDB(int partID, int studyID)
        {
            DbStatus         manageParticipantStatus = new DbStatus();
            Studyparticipant studpart = _context.Studyparticipant.FirstOrDefault(x => x.IdStudy == studyID && x.IdParticipant == partID);

            if (studpart == null)
            {
                Participant participant = _context.Participant.FirstOrDefault(part => part.IdParticipant == partID);
                if (participant != null)
                {
                    //Participant exists, but is not enrolled.
                    studpart = new Studyparticipant();
                    studpart.IdParticipant = partID;
                    studpart.IdStudy       = studyID;
                    _context.Studyparticipant.Add(studpart);
                    _context.SaveChanges();
                    manageParticipantStatus.success = true;
                }
                else
                {
                    //Participant with this ID does not exists.
                    manageParticipantStatus.success      = false;
                    manageParticipantStatus.errormessage = "Participant with this ID does not exist in the system";
                }
            }
            else
            {
                //Participant allready enrolled in study
                manageParticipantStatus.success      = false;
                manageParticipantStatus.errormessage = "Participant is already enrolled instudy.";
            }
            return(manageParticipantStatus);
        }
Ejemplo n.º 3
0
        public DbStatus LoginResearcherDB(string email, string password)
        {
            DbStatus   status     = new DbStatus();
            Researcher researcher = _context.Researcher.FirstOrDefault(res => res.Email == email);

            if (researcher != null)
            {
                if (researcher.Password == password)
                {
                    //Successfull login
                    status.success    = true;
                    status.researcher = researcher;
                }
                else
                {
                    //Wrong password
                    status.success      = false;
                    status.errormessage = "Wrong password";
                }
            }
            else
            {
                //No researcher with this email exists in database
                status.errormessage = "No researcher with this email exists";
            }

            return(status);
        }
Ejemplo n.º 4
0
        public DbStatus LoginParticipantDB(string email, string password)
        {
            DbStatus    status      = new DbStatus();
            Participant participant = _context.Participant.FirstOrDefault(part => part.Email == email);

            if (participant != null)
            {
                if (participant.Password == password)
                {
                    //Successfull login
                    status.success     = true;
                    status.participant = participant;
                }
                else
                {
                    //Wrong password
                    status.errormessage = "Wrong password";
                }
            }
            else
            {
                //No participant with this email exists in database
                status.errormessage = "No participant with this email exists";
            }

            return(status);
        }
        public DbStatus GetParticipantEmailDB(int partID)
        {
            DbStatus    manageParticipantStatus = new DbStatus();
            Participant participant             = _context.Participant.FirstOrDefault(part => part.IdParticipant == partID);

            if (participant != null)
            {
                manageParticipantStatus.success          = true;
                manageParticipantStatus.participantEmail = participant.Email;
            }
            else
            {
                manageParticipantStatus.success      = false;
                manageParticipantStatus.errormessage = "No participant with this ID exists";
            }
            return(manageParticipantStatus);
        }
        public DbStatus RemoveParticipantFromStudyDB(int partID, int studyID)
        {
            DbStatus         manageParticipantStatus = new DbStatus();
            Studyparticipant studPart = _context.Studyparticipant.FirstOrDefault(x => x.IdParticipant == partID && x.IdStudy == studyID);

            if (studPart != null)
            {
                //Participant is enrolled in study
                _context.Studyparticipant.Remove(studPart);
                _context.SaveChanges();
                manageParticipantStatus.success = true;
            }
            else
            {
                //Participant is not enrolled in study
                manageParticipantStatus.errormessage = "Participant is not enrolled in study";
                manageParticipantStatus.success      = false;
            }
            return(manageParticipantStatus);
        }
Ejemplo n.º 7
0
        public DbStatus ChangePasswordParticipantDB(Participant participant, string oldPassword)
        {
            Participant oldParticipant = _context.Participant.FirstOrDefault(part => part.IdParticipant == participant.IdParticipant);
            DbStatus    status         = new DbStatus();

            if (oldParticipant.Password == oldPassword)
            {
                //Old password matches and password will be changed.
                oldParticipant.Password = participant.Password;
                _context.Participant.Update(oldParticipant);
                _context.SaveChanges();
                status.success = true;
            }
            else
            {
                //Old password did not match. Password will not be changed.
                status.success      = false;
                status.errormessage = "The old password was incorrect. Please try again";
            }
            return(status);
        }
Ejemplo n.º 8
0
        public DbStatus ChangePasswordResearcherDB(Researcher researcher, string oldPassword)
        {
            Researcher oldResearcher = _context.Researcher.FirstOrDefault(res => res.IdResearcher == researcher.IdResearcher);
            DbStatus   status        = new DbStatus();

            if (oldResearcher.Password == oldPassword)
            {
                //The old password matches, and will be changed to new one
                oldResearcher.Password = researcher.Password;
                _context.Researcher.Update(oldResearcher);
                _context.SaveChanges();
                status.success = true;
            }
            else
            {
                //Old password did not match. Password will not be changed
                status.success      = false;
                status.errormessage = "The old password was incorrect. Please try again";
            }
            return(status);
        }