Example #1
0
        public ParticipantJourneyViewModel RetrieveParticipantJourney(ParticipantJourneySearchViewModel psm, out string message, out MessageType messageType)
        {
            message     = string.Empty;
            messageType = MessageType.ERROR;

            ParticipantJourneyViewModel result = null;

            if (psm == null)
            {
                message = "Parameter cannot be null";
            }

            else if (string.IsNullOrEmpty(psm.Nric) || psm.PHSEventId == 0)
            {
                message = "Please enter valid NRIC and select Live Event";
            }

            else if (!NricChecker.IsNRICValid(psm.Nric))
            {
                message = "Invalid Nric";
            }

            else
            {
                using (var unitOfWork = CreateUnitOfWork())
                {
                    PHSEvent phsEvent = unitOfWork.Events.GetAllActiveEvents().Where(e => e.PHSEventID == psm.PHSEventId).FirstOrDefault();

                    if (phsEvent == null)
                    {
                        message = "Screening Event is not active";
                    }

                    else
                    {
                        Participant participant = unitOfWork.Participants.FindParticipant(psm.Nric, psm.PHSEventId);

                        if (participant != null)
                        {
                            result = new ParticipantJourneyViewModel(participant, psm.PHSEventId);
                        }

                        else
                        {
                            messageType = MessageType.PROMPT;

                            PreRegistration preRegistration = unitOfWork.PreRegistrations.FindPreRegistration(p => p.Nric.Equals(psm.Nric));
                            if (preRegistration == null)
                            {
                                message = "No registration record found. Do you want to register this Nric?";
                            }

                            else
                            {
                                message = "Do you want to register this Nric?";
                            }
                        }
                    }
                }
            }

            return(result);
        }
Example #2
0
        public static bool SubmittedValueIsValid(this TemplateFieldViewModel field, FormCollection form)
        {
            var    fType = field.FieldType.ToString().ToTitleCase();
            string value = "";

            switch (field.FieldType)
            {
            case Constants.TemplateFieldType.TEXTBOXNUMBER:
                string textnumber = form.SubmittedFieldValue(field.DomId, fType.ToTitleCase());
                if (string.IsNullOrEmpty(textnumber))
                {
                    return(true);
                }
                return(textnumber.IsNumeric());

            case Constants.TemplateFieldType.NRICPICKER:
                string icNumber = form.SubmittedFieldValue(field.DomId, fType.ToTitleCase());
                // string icFirstDigit = form.SubmittedFieldValue(field.DomId, "FirstDigit");
                // string icLastDigit = form.SubmittedFieldValue(field.DomId, "LastDigit");

                return(NricChecker.IsNRICValid(icNumber));

            case Constants.TemplateFieldType.CHECKBOX:
                value = form.SubmittedFieldValue(field.DomId, fType.ToTitleCase());
                if (!value.IsNullOrEmpty() && value.Contains("OthersOption"))
                {
                    string othersOptionValue = form.SubmittedFieldValue(field.DomId, "OthersOption");
                    if (othersOptionValue.IsNullOrEmpty())
                    {
                        return(false);
                    }
                }
                return(true);

            case Constants.TemplateFieldType.RADIOBUTTON:
                value = form.SubmittedFieldValue(field.DomId, fType.ToTitleCase());
                if (!value.IsNullOrEmpty() && value.Equals("OthersOption"))
                {
                    value = form.SubmittedFieldValue(field.DomId, "OthersOption");
                    if (value.IsNullOrEmpty())
                    {
                        return(false);
                    }
                }
                return(true);

            case Constants.TemplateFieldType.EMAIL:
                value = form.SubmittedFieldValue(field.DomId, fType.ToTitleCase());
                if (value.IsNullOrEmpty())
                {
                    return(true);
                }
                return(value.IsValidEmail());

            case Constants.TemplateFieldType.ADDRESS:
                return(true);

            case Constants.TemplateFieldType.PHONE:
                var area   = form.SubmittedFieldValue(field.DomId, "AreaCode");
                var number = form.SubmittedFieldValue(field.DomId, "Number");
                if (area.IsNullOrEmpty() && number.IsNullOrEmpty())
                {
                    return(true);
                }
                else if ((area.IsNullOrEmpty() && !number.IsNullOrEmpty()) || (!area.IsNullOrEmpty() && number.IsNullOrEmpty()))
                {
                    return(false);
                }
                else
                {
                    return(area.IsNumeric() && number.IsNumeric());
                }

            case Constants.TemplateFieldType.BIRTHDAYPICKER:
                var day   = form.SubmittedFieldValue(field.DomId, "Day");
                var month = form.SubmittedFieldValue(field.DomId, "Month");
                var year  = form.SubmittedFieldValue(field.DomId, "Year");

                if (day.IsNullOrEmpty() && month.IsNullOrEmpty() && year.IsNullOrEmpty())
                {
                    return(true);
                }

                try
                {
                    if (!string.IsNullOrEmpty(day))
                    {
                        int dayValue = Int32.Parse(day);
                        if (dayValue <= 0 || dayValue >= 32)
                        {
                            return(false);
                        }
                    }

                    if (!string.IsNullOrEmpty(month))
                    {
                        int monthValue = Int32.Parse(month);
                        if (monthValue <= 0 || monthValue >= 13)
                        {
                            return(false);
                        }
                    }

                    if (!string.IsNullOrEmpty(year))
                    {
                        int yearValue = Int32.Parse(year);
                        if (yearValue <= 1916 || yearValue >= 2999)
                        {
                            return(false);
                        }
                    }


                    return(true);
                }

                catch (FormatException)
                {
                    return(false);
                }

            /*
             * var dateValue = "{0}-{1}-{2}".FormatWith(month, day, year);
             * var format = new string[] { "M-dd-yyyy" };
             * DateTime date;
             * return DateTime.TryParseExact(dateValue, "M-dd-yyyy", CultureInfo.InvariantCulture, DateTimeStyles.NoCurrentDateDefault, out date);
             */
            case Constants.TemplateFieldType.FILEPICKER:
                HttpPostedFile file            = HttpContext.Current.Request.Files[SubmittedFieldName(field.DomId, fType.ToTitleCase())];
                var            maxSize         = field.MaxFileSize * 1024;
                var            minSize         = field.MinFileSize * 1024;
                var            validExtensions = field.ValidFileExtensions;

                if (file != null && file.ContentLength > 0)
                {
                    var extension = System.IO.Path.GetExtension(file.FileName);
                    // check filesize is within range of Max and Min
                    if (!(file.ContentLength >= minSize && file.ContentLength <= maxSize))
                    {
                        return(false);
                    }

                    // check file extension is valid
                    if (!validExtensions.IsNullOrEmpty())
                    {
                        var  validExtensionArr = validExtensions.Split(",").Select(ext => ext.Trim()).ToList();
                        bool isValidExt        = false;
                        foreach (var ext in validExtensionArr)
                        {
                            var updatedExt = ext;
                            if (!ext.StartsWith("."))
                            {
                                updatedExt = "." + ext;
                            }

                            if (updatedExt.IsTheSameAs(extension))
                            {
                                isValidExt = true;
                            }
                        }

                        return(isValidExt);
                    }
                }

                return(true);
            }

            return(true);
        }
Example #3
0
        public string RegisterParticipant(ParticipantJourneySearchViewModel psm)
        {
            string result = null;

            if (psm == null)
            {
                return("Parameter cannot be null");
            }

            else if (string.IsNullOrEmpty(psm.Nric) || psm.PHSEventId == 0)
            {
                return("Please enter valid NRIC and select Live Event");
            }

            else if (!NricChecker.IsNRICValid(psm.Nric))
            {
                return("Invalid Nric");
            }

            else
            {
                using (var unitOfWork = CreateUnitOfWork())
                {
                    PHSEvent phsEvent = unitOfWork.Events.GetEventWithModalityForm(psm.PHSEventId);

                    if (phsEvent == null)
                    {
                        return("Screening Event is not active");
                    }

                    else
                    {
                        Participant participant = unitOfWork.Participants.FindParticipant(psm.Nric);

                        if (participant != null)
                        {
                            if (participant.PHSEvents.All(e => e.PHSEventID == psm.PHSEventId))
                            {
                                return("Invalid register participant");
                            }
                        }

                        PreRegistration preRegistration = unitOfWork.PreRegistrations.FindPreRegistration(p => p.Nric.Equals(psm.Nric));

                        using (TransactionScope scope = new TransactionScope())
                        {
                            if (participant == null)
                            {
                                participant = new Participant()
                                {
                                    Nric = psm.Nric
                                };

                                copyPreRegistrationToParticipant(participant, preRegistration);
                                unitOfWork.Participants.AddParticipantWithPHSEvent(participant, phsEvent);
                            }

                            else
                            {
                                copyPreRegistrationToParticipant(participant, preRegistration);
                                unitOfWork.Participants.AddPHSEventToParticipant(participant, phsEvent);
                            }

                            foreach (var modality in phsEvent.Modalities)
                            {
                                if (modality.IsMandatory)
                                {
                                    foreach (var form in modality.Forms)
                                    {
                                        ParticipantJourneyModality participantJourneyModality = new ParticipantJourneyModality()
                                        {
                                            ParticipantID = participant.ParticipantID,
                                            PHSEventID    = phsEvent.PHSEventID,
                                            FormID        = form.FormID,
                                            ModalityID    = modality.ModalityID
                                        };

                                        if (!Constants.IsFormForSubmit(form.FormID))
                                        {
                                            participantJourneyModality.TemplateID = form.Templates.FirstOrDefault().TemplateID;
                                            participantJourneyModality.EntryId    = new Guid("10000000-9999-9999-9999-000000000001");
                                        }

                                        participant.ParticipantJourneyModalities.Add(participantJourneyModality);
                                    }
                                }
                            }

                            unitOfWork.Complete();
                            scope.Complete();

                            result = "success";
                        }
                    }
                }
            }

            return(result);
        }