Пример #1
0
        public DbStatus VerifyResearcherDB(int resID)
        {
            Researcher researcher             = _context.Researcher.FirstOrDefault(res => res.IdResearcher == resID);
            DbStatus   verifyResearcherStatus = new DbStatus();

            if (researcher != null)
            {
                if (researcher.Isverified == false)
                {
                    //Verify researcher
                    researcher.Isverified = true;
                    _context.Update(researcher);
                    _context.SaveChanges();
                    verifyResearcherStatus.success = true;
                }
                else
                {
                    //Researcher was all ready verified
                    verifyResearcherStatus.success      = false;
                    verifyResearcherStatus.errormessage = "Researcher is all ready verified";
                }
            }
            else
            {
                //Researcher does not exists
                verifyResearcherStatus.success      = false;
                verifyResearcherStatus.errormessage = "Researcher with this ID does not exists";
            }
            return(verifyResearcherStatus);
        }
Пример #2
0
        public void CreateStudyDB(Study study, Inclusioncriteria inclusioncriteria)
        {
            //Adds the study to the database and saves
            _context.Study.Add(study);
            _context.SaveChanges();


            //Retrieves the id from the study just saved and sets the study_id in inclusioncriteria.
            var dbStudy = (_context.Study.FirstOrDefault(stud =>
                                                         stud.Name == study.Name && stud.DateCreated == study.DateCreated)) ??
                          _context.Study.Local.FirstOrDefault(stud =>
                                                              stud.Name == study.Name && stud.DateCreated == study.DateCreated);

            inclusioncriteria.IdStudy = dbStudy.IdStudy;

            //Sets the direct study link with the generated ID
            if (dbStudy != null)
            {
                //Todo OBS!!! Direct Study link currently hardcoded - fix or rewrite when published.
                dbStudy.DirectStudyLink = "http://localhost:61728/ViewStudy/ViewStudy?studyID=" + dbStudy.IdStudy;
                _context.Study.Update(dbStudy);
            }

            //Saves the inclusioncriteria and the study link
            _context.Inclusioncriteria.Add(inclusioncriteria);
            _context.SaveChanges();
        }
        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);
        }
Пример #4
0
 public bool RegisterParticipantDB(Participant participant)
 {
     if (_context.Participant.Any(part => part.Email == participant.Email))
     {
         //Email allready exists
         return(false);
     }
     else
     {
         //Register participant
         _context.Participant.Add(participant);
         _context.SaveChanges();
         return(true);
     }
 }
Пример #5
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);
        }