Exemple #1
0
        public void SetUp()
        {
            _ministryPlatformService = new Mock <IMinistryPlatformService>();
            _authService             = new Mock <IAuthenticationRepository>();
            _configWrapper           = new Mock <IConfigurationWrapper>();
            _dbConnection            = new Mock <IDbConnection>();
            _ministryPlatformRest    = new Mock <IMinistryPlatformRestRepository>();

            _configWrapper.Setup(m => m.GetEnvironmentVarAsString("API_USER")).Returns("uid");
            _configWrapper.Setup(m => m.GetEnvironmentVarAsString("API_PASSWORD")).Returns("pwd");
            _authService.Setup(m => m.Authenticate(It.IsAny <string>(), It.IsAny <string>())).Returns(new AuthToken
            {
                AccessToken = "ABC",
                ExpiresIn   = 123
            });

            _fixture = new FormSubmissionRepository(_ministryPlatformService.Object, _dbConnection.Object, _authService.Object, _configWrapper.Object, _ministryPlatformRest.Object);

            _mockAnswer1 = new MpFormAnswer
            {
                FieldId               = 375,
                FormResponseId        = responseId,
                OpportunityResponseId = 7329,
                Response              = "Test Last Name",
                EventParticipantId    = null
            };

            _mockAnswer2 = new MpFormAnswer
            {
                FieldId               = 376,
                FormResponseId        = responseId,
                OpportunityResponseId = 7329,
                Response              = "Test First Name",
                EventParticipantId    = null
            };

            _mockAnswer3 = new MpFormAnswer
            {
                FieldId               = 377,
                FormResponseId        = responseId,
                OpportunityResponseId = 7329,
                Response              = "Test Middle Initial",
                EventParticipantId    = null
            };

            _mockForm = new MpFormResponse
            {
                FormId                = 17,
                ContactId             = 2389887,
                OpportunityId         = 313,
                OpportunityResponseId = 7329,
                FormAnswers           = new List <MpFormAnswer>
                {
                    _mockAnswer1,
                    _mockAnswer2,
                    _mockAnswer3
                }
            };
        }
Exemple #2
0
        public List <KeyValuePair <string, string> > SaveFormSubmission(FormCollection values, string recipients, DateTime date, int formID, int formSubmissionID = 0)
        {
            Dictionary <string, string> dictValues = values.AllKeys.ToDictionary(k => k, v => values[v]);
            string stringValues = String.Empty;

            foreach (var item in dictValues)
            {
                if (item.Key.Contains("recaptcha") || item.Key.Contains("FormID") || item.Key.Contains("RecipientEmail") || item.Key.Contains("subscribe"))
                {
                    continue;
                }

                if (item.Key.Contains("radio"))
                {
                    var itemID      = int.Parse(item.Key.Replace("radio", ""));
                    var contactItem = FormItemRepository.GetByID(itemID);
                    var value       = contactItem.tbl_FormItemValues.FirstOrDefault(fiv => fiv.FIV_Value == int.Parse(item.Value));
                    stringValues += String.Format("{0}:{1}###", contactItem.FI_Text, value.FIV_Text);
                    continue;
                }

                if (item.Key.Contains("select"))
                {
                    var itemID      = int.Parse(item.Key.Replace("select", ""));
                    var contactItem = FormItemRepository.GetByID(itemID);
                    var value       = contactItem.tbl_FormItemValues.FirstOrDefault(fiv => fiv.FIV_Value == int.Parse(item.Value));
                    stringValues += String.Format("{0}:{1}###", contactItem.FI_Text, value.FIV_Text);
                    continue;
                }

                if (item.Key.Contains("checkbox"))
                {
                    var itemID      = int.Parse(item.Key.Replace("checkbox", ""));
                    var contactItem = FormItemRepository.GetByID(itemID);
                    foreach (var key in item.Value.Split(','))
                    {
                        var value = contactItem.tbl_FormItemValues.FirstOrDefault(fiv => fiv.FIV_Value == int.Parse(key));
                        stringValues += String.Format("{0}:{1}###", contactItem.FI_Text, value.FIV_Text);
                    }
                    continue;
                }

                stringValues += String.Format("{0}:{1}###", item.Key, item.Value);
            }
            stringValues.TrimEnd('#');

            List <KeyValuePair <string, string> > listValues = stringValues.Split(new[] { "###" }, StringSplitOptions.RemoveEmptyEntries).Select(s => new KeyValuePair <string, string>(s.Substring(0, s.IndexOf(':')), s.Substring(s.IndexOf(':') + 1))).ToList();

            FormSubmissionRepository.SaveFormSubmission(stringValues, recipients, date, formID, formSubmissionID);
            return(listValues);
        }
 public FormController(FormRepository formRepository, FormSubmissionRepository formSubmissionRepository, IServiceProvider serviceProvider, IUserSession userSession) : base(serviceProvider, userSession)
 {
     this.FormSubmissionRepository = formSubmissionRepository;
     this.FormRepository           = formRepository;
 }
 public FormController(FormRepository formRepository, FormSubmissionRepository formSubmissionRepository, ISendTemplates emailTemplateRepository = null)
 {
     this.EmailTemplateRepository  = emailTemplateRepository;
     this.FormSubmissionRepository = formSubmissionRepository;
     this.FormRepository           = formRepository;
 }
Exemple #5
0
 public tbl_FormSubmission MarkFormSubmissionAsRead(int formSubmissionID)
 {
     return(FormSubmissionRepository.MarkAsRead(formSubmissionID));
 }
Exemple #6
0
 public tbl_FormSubmission GetFormSubmissionByID(int formSubmissionID)
 {
     return(formSubmissionID == 0 ? FormSubmissionRepository.GetNewest() : FormSubmissionRepository.GetByID(formSubmissionID));
 }
Exemple #7
0
 public List <tbl_FormSubmission> GetFormSubmissionsByFormID(int formID)
 {
     return(FormSubmissionRepository.GetByFormID(formID).ToList());
 }
Exemple #8
0
 public List <tbl_FormSubmission> GetAllFormSubmissions()
 {
     return(FormSubmissionRepository.GetAll().ToList());
 }
Exemple #9
0
 public bool DeleteFormSubmission(int formSubmissionID)
 {
     return(FormSubmissionRepository.DeleteByID(formSubmissionID));
 }