public IActionResult Create(SendingModel sModel, int studyID)
        {
            ViewStudyModelHelper viewStudyModelHelper = new ViewStudyModelHelper();

            sModel.Study = viewStudyModelHelper.createViewStudyModel(studyID);
            if (ModelState.IsValid)
            {
                try
                {
                    // Convert to create the right format
                    EmailHelper emailHelper = new EmailHelper();
                    emailHelper.SendMessages(sModel, studyID);

                    return(RedirectToAction("Researcher", "Homepage"));
                }
                catch (Exception e)
                {
                    //Should store error in a internal log.
                    return(View("Index"));
                }
            }
            IManageParticipantHandler mph1          = new ManageParticipantHandler(new bachelordbContext());
            List <Participant>        participants1 = mph1.GetAllEligibalParticipants(sModel.Study.inclusioncriteria, studyID);

            sModel.ParticipantCount = participants1.Count;
            return(View("index", sModel));
        }
예제 #2
0
        public void PrefillTextArea(SendingModel sModel)
        {
            if (sModel.Mail == null)
            {
                sModel.Mail = new EmailModel();
            }

            sModel.Mail.MailBody = "<p>Hallo!</p>\r\n<p>&nbsp;</p>" +
                                   " <p>We are contacting you because we are in a need of new participants!</p>\r\n" + Environment.NewLine +
                                   " <p>The Description is as follows:" + sModel.Study.study.Description.ToString() + "</p>\r\n" + System.Environment.NewLine +
                                   "<p>The pay will be as follows: " + sModel.Study.study.Pay + "kr" + "</p>\r\n" + System.Environment.NewLine +
                                   "<p>The duration will be as follows:" + sModel.Study.study.Duration + "</p>\r\n" + System.Environment.NewLine +
                                   "<p>If you want more information you can read more about the study here " + sModel.Study.study.DirectStudyLink + "</p>\r\n" +
                                   "If you are interested please contact " + sModel.Study.researcher.FirstName + " " + sModel.Study.researcher.LastName + "  at " + sModel.Study.researcher.Email;
        }
        public IActionResult Index(int studyID)
        {
            ViewStudyModelHelper viewStudyModelHelper   = new ViewStudyModelHelper();
            SendingModel         sendToParticipantModel = new SendingModel();

            sendToParticipantModel.Study = viewStudyModelHelper.createViewStudyModel(studyID);

            EmailHelper emailHelper = new EmailHelper();

            emailHelper.PrefillTextArea(sendToParticipantModel);

            IManageParticipantHandler mph          = new ManageParticipantHandler(new bachelordbContext());
            List <Participant>        participants = mph.GetAllEligibalParticipants(sendToParticipantModel.Study.inclusioncriteria, studyID);

            sendToParticipantModel.ParticipantCount = participants.Count;

            return(View(sendToParticipantModel));
        }
예제 #4
0
        public void SendToParticipants(SendingModel sModel, int studyId)
        {
            //Getting participants from DB
            IManageParticipantHandler mph          = new ManageParticipantHandler(new bachelordbContext());
            List <Participant>        participants =
                mph.GetAllEligibalParticipants(sModel.Study.inclusioncriteria, studyId);

            foreach (var participant in participants)
            {
                var message = new MimeMessage();
                message.From.Add(new MailboxAddress("Tandlægehøjskolen", "donotreplyTandlægeHø[email protected]"));
                message.To.Add(new MailboxAddress("Participant for Tandlægehøjskolen", participant.Email));

                var builder = new BodyBuilder();



                builder.HtmlBody = sModel.Mail.MailBody + System.Environment.NewLine + "" + System.Environment.NewLine +
                                   "" + System.Environment.NewLine;


                SendingWithSmtpClient(builder, message, sModel.Mail.Subject);
            }
        }
예제 #5
0
        public void SendMessages(SendingModel sModel, int studyId)
        {
            Thread t = new Thread(() => SendToParticipants(sModel, studyId));

            t.Start();
        }