Пример #1
0
        /// <summary>
        /// Submits the form and its fields
        /// </summary>
        /// <param name="form"></param>
        /// <param name="formFieldWithValueModels"></param>
        /// <param name="userId"></param>
        /// <returns></returns>
        public async Task <FormSubmission> SubmitFormAsync(Form form, Dictionary <FormField, string> formFieldWithValueModels, string userId, string patientId)
        {
            var formSubmission = new FormSubmission()
            {
                FormSubmissionId = Guid.NewGuid().ToString(),
                PatientId        = patientId,
                FormName         = form.Name,
                Description      = form.Description,
                UserId           = userId,
                DateCreated      = DateTime.Now,
                DateUpdated      = DateTime.Now
            };

            foreach (var formFieldWithValueModel in formFieldWithValueModels)
            {
                formSubmission.FormFieldSubmissions.Add(
                    new FormFieldSubmission()
                {
                    FormFieldName         = formFieldWithValueModel.Key.FieldName,
                    FormFieldSubmissionId = Guid.NewGuid().ToString(),
                    FormFieldValue        = formFieldWithValueModel.Value,
                    FormInputType         = formFieldWithValueModel.Key.FormInputType,
                    FormSubmission        = formSubmission,
                    FormSubmissionId      = formSubmission.FormSubmissionId,
                }
                    );
            }

            _applicationDbContext.FormSubmissions.Add(formSubmission);
            await _applicationDbContext.SaveChangesAsync();

            return(formSubmission);
        }
Пример #2
0
        public async void can_get_draft_data()
        {
            FormsClient             forms           = new FormsClient(ACCESS_KEY, SECRET_KEY, TenantName.ONEBLINK_TEST);
            FormSubmission <object> draftSubmission = await forms.GetFormSubmission <object>(this.draftFormId, this.draftDataId, true);

            Assert.NotNull(draftSubmission);
            Assert.NotNull(draftSubmission.definition);
            Assert.NotNull(draftSubmission.submission);
        }
Пример #3
0
    public async System.Threading.Tasks.Task ListForms2Async()
    {
        var            tenantId = Guid.Parse(TenantId);
        FormDefinition form     = await this.client.CreateFormAsync(
            new CreateFormRequest
        {
            Name   = "TestForm",
            Fields = new List <FormFieldDefinition>
            {
                new FormFieldDefinition
                {
                    Name = "Name",
                    Type = "string",
                },
                new FormFieldDefinition
                {
                    Name = "Age",
                    Type = "int",
                },
            },
        },
            tenantId).ConfigureAwait(false);

        form.Should().NotBeNull();

        form = await this.client.GetFormAsync(tenantId, form.FormId).ConfigureAwait(false);

        form.Should().NotBeNull();

        FormSubmission submission = await this.client.SubmitFormAsync(
            form.FormId,
            new Dictionary <string, string>
        {
            ["Name"] = "Test",
            ["Age"]  = "30",
        },
            new Dictionary <string, HttpFile>
        {
            ["ProfilePicture"] = new HttpFile(File.OpenRead("350x350.png"), "test.png", "image/png"),
        },
            tenantId).ConfigureAwait(false);

        submission.Should().NotBeNull();

        submission = await this.client.GetSubmissionAsync(tenantId, form.FormId, submission.SubmissionId).ConfigureAwait(false);

        submission.Should().NotBeNull();

#pragma warning disable CA2000 // Dispose objects before losing scope
        HttpFile attachment = await this.client.GetSubmissionAttachmentAsync(form.FormId, submission.SubmissionId, "ProfilePicture", tenantId).ConfigureAwait(false);

#pragma warning restore CA2000 // Dispose objects before losing scope
        attachment.Should().NotBeNull();

        ICollection <FormDefinition> forms = await this.client.ListFormsAsync(tenantId).ConfigureAwait(false);
    }
Пример #4
0
        public List <FormSubmission> GetAllByFormDocumentId(int FormDocumentID)
        {
            FormSubmissionDAC     _formSubmissionComponent = new FormSubmissionDAC();
            IDataReader           reader = _formSubmissionComponent.GetAllFormSubmission("FormDocumentID = " + FormDocumentID).CreateDataReader();
            List <FormSubmission> _formSubmissionList = new List <FormSubmission>();

            while (reader.Read())
            {
                if (_formSubmissionList == null)
                {
                    _formSubmissionList = new List <FormSubmission>();
                }
                FormSubmission _formSubmission = new FormSubmission();
                if (reader["FormSubmissionId"] != DBNull.Value)
                {
                    _formSubmission.FormSubmissionId = Convert.ToInt32(reader["FormSubmissionId"]);
                }
                if (reader["UserId"] != DBNull.Value)
                {
                    _formSubmission.UserId = Convert.ToInt32(reader["UserId"]);
                }
                if (reader["IsAnonymous"] != DBNull.Value)
                {
                    _formSubmission.IsAnonymous = Convert.ToBoolean(reader["IsAnonymous"]);
                }
                if (reader["SubmissionDate"] != DBNull.Value)
                {
                    _formSubmission.SubmissionDate = Convert.ToDateTime(reader["SubmissionDate"]);
                }
                if (reader["IPAddress"] != DBNull.Value)
                {
                    _formSubmission.IPAddress = Convert.ToString(reader["IPAddress"]);
                }
                if (reader["IsValid"] != DBNull.Value)
                {
                    _formSubmission.IsValid = Convert.ToBoolean(reader["IsValid"]);
                }
                if (reader["EmailSent"] != DBNull.Value)
                {
                    _formSubmission.EmailSent = Convert.ToBoolean(reader["EmailSent"]);
                }
                if (reader["SMSSent"] != DBNull.Value)
                {
                    _formSubmission.SMSSent = Convert.ToBoolean(reader["SMSSent"]);
                }
                if (reader["FormDocumentID"] != DBNull.Value)
                {
                    _formSubmission.FormDocumentID = Convert.ToInt32(reader["FormDocumentID"]);
                }
                _formSubmission.NewRecord = false;
                _formSubmissionList.Add(_formSubmission);
            }
            reader.Close();
            return(_formSubmissionList);
        }
Пример #5
0
        public void DoProcess(ExecuteSubmitActionsEventArgs args)
        {
            var formEvent = new FormSubmission(DateTime.UtcNow)
            {
                FormId = args.FormSubmitContext.FormId
            };

            args.FormSubmitContext.Fields.ToList().ForEach(f => formEvent.CustomValues.Add(f.ItemId, f.GetStringValue()));

            _service.RegisterInteractionEvent(formEvent);
        }
Пример #6
0
        public bool Insert(FormSubmission formsubmission)
        {
            int autonumber = 0;
            FormSubmissionDAC formsubmissionComponent = new FormSubmissionDAC();
            bool endedSuccessfuly = formsubmissionComponent.InsertNewFormSubmission(ref autonumber, formsubmission.UserId, formsubmission.IsAnonymous, formsubmission.SubmissionDate, formsubmission.IPAddress, formsubmission.IsValid, formsubmission.EmailSent, formsubmission.SMSSent, formsubmission.FormDocumentID);

            if (endedSuccessfuly)
            {
                formsubmission.FormSubmissionId = autonumber;
            }
            return(endedSuccessfuly);
        }
Пример #7
0
    public async System.Threading.Tasks.Task ListFormSubmissionsAsync()
    {
        var tenantId = Guid.Parse(TenantId);
        ICollection <FormDefinition> forms = await this.client.ListFormsAsync(tenantId).ConfigureAwait(false);

        FormDefinition form = forms.First();

        ICollection <FormSubmissionSummary> submissions = await this.client.ListSubmissionsAsync(tenantId, form.FormId).ConfigureAwait(false);

        FormSubmissionSummary submissionInfo = submissions.FirstOrDefault(s => s.AttachmentCount > 0);
        FormSubmission        submission     = await this.client.GetSubmissionAsync(tenantId, form.FormId, submissionInfo.SubmissionId).ConfigureAwait(false);
    }
Пример #8
0
        /// <summary>
        /// Gets the form submission by identifier.
        /// </summary>
        /// <param name="FormSubmissionID">The form submission identifier.</param>
        /// <returns></returns>
        public FormSubmission GetFormSubmissionByID(int FormSubmissionID)
        {
            var db = ObjectContextFactory.Create();
            FormSubmissionDb formsubmissiondb = db.FormSubmissions.Where(i => i.FormSubmissionID == FormSubmissionID).FirstOrDefault();

            if (formsubmissiondb == null)
            {
                return(null);
            }
            FormSubmission formsubmission = Mapper.Map <FormSubmissionDb, FormSubmission>(formsubmissiondb);

            return(formsubmission);
        }
Пример #9
0
        private static void RegisterFormSubmissionFacet(XConnectClient client, Interaction interaction)
        {
            FormSubmission formSubmission = new FormSubmission(DateTime.UtcNow)
            {
                FormId = Guid.NewGuid()
            };

            formSubmission.CustomValues.Add(Guid.NewGuid().ToString(), "Books");
            formSubmission.CustomValues.Add(Guid.NewGuid().ToString(), "1");
            formSubmission.CustomValues.Add(Guid.NewGuid().ToString(), "5");

            interaction.Events.Add(formSubmission);
        }
Пример #10
0
        public FormSubmission GetByID(int _formSubmissionId)
        {
            FormSubmissionDAC _formSubmissionComponent = new FormSubmissionDAC();
            IDataReader       reader          = _formSubmissionComponent.GetByIDFormSubmission(_formSubmissionId);
            FormSubmission    _formSubmission = null;

            while (reader.Read())
            {
                _formSubmission = new FormSubmission();
                if (reader["FormSubmissionId"] != DBNull.Value)
                {
                    _formSubmission.FormSubmissionId = Convert.ToInt32(reader["FormSubmissionId"]);
                }
                if (reader["UserId"] != DBNull.Value)
                {
                    _formSubmission.UserId = Convert.ToInt32(reader["UserId"]);
                }
                if (reader["IsAnonymous"] != DBNull.Value)
                {
                    _formSubmission.IsAnonymous = Convert.ToBoolean(reader["IsAnonymous"]);
                }
                if (reader["SubmissionDate"] != DBNull.Value)
                {
                    _formSubmission.SubmissionDate = Convert.ToDateTime(reader["SubmissionDate"]);
                }
                if (reader["IPAddress"] != DBNull.Value)
                {
                    _formSubmission.IPAddress = Convert.ToString(reader["IPAddress"]);
                }
                if (reader["IsValid"] != DBNull.Value)
                {
                    _formSubmission.IsValid = Convert.ToBoolean(reader["IsValid"]);
                }
                if (reader["EmailSent"] != DBNull.Value)
                {
                    _formSubmission.EmailSent = Convert.ToBoolean(reader["EmailSent"]);
                }
                if (reader["SMSSent"] != DBNull.Value)
                {
                    _formSubmission.SMSSent = Convert.ToBoolean(reader["SMSSent"]);
                }
                if (reader["FormDocumentID"] != DBNull.Value)
                {
                    _formSubmission.FormDocumentID = Convert.ToInt32(reader["FormDocumentID"]);
                }
                _formSubmission.NewRecord = false;
            }
            reader.Close();
            return(_formSubmission);
        }
Пример #11
0
        public async Task <IActionResult> OnGetAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            FormSubmission = await _context.FormSubmission.FirstOrDefaultAsync(m => m.ID == id);

            if (FormSubmission == null)
            {
                return(NotFound());
            }
            return(Page());
        }
Пример #12
0
        public IActionResult FormSubmit(FormSubmission model)
        {
            var recaptcha = this.Request.Form["g-recaptcha-response"];

            // TODO: Check if this is a valid anti-bot response

            model.DateEntered = DateTime.UtcNow;
            using (var connection = new SqlConnection(this.appSettings.Options.DataConnectionString))
            {
                connection.Execute(
                    "INSERT INTO [FormSubmission] ([Name], [NumberOfTickets], [ContactChoice], [PhoneNumber], [EmailAddress], [AdditionalInformation], [DateEntered]) VALUES (@Name, @NumberOfTickets, @ContactChoice, @PhoneNumber, @EmailAddress, @AdditionalInformation, @DateEntered)",
                    model);
            }

            return(this.RedirectToAction("Confirmation"));
        }
Пример #13
0
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            FormSubmission = await _context.FormSubmission.FindAsync(id);

            if (FormSubmission != null)
            {
                _context.FormSubmission.Remove(FormSubmission);
                await _context.SaveChangesAsync();
            }

            return(RedirectToPage("./Index"));
        }
Пример #14
0
        public async void get_submission_data_should_throw_oneblink_exception()
        {
            FormsClient forms = new FormsClient("123", "aaaaaaaaaaaaaaabbbbbbbbbbbbbbbcccccccccccccccc");

            try
            {
                FormSubmission <object> formSubmission = await forms.GetFormSubmission <object>(this.formId, this.submissionId);

                Assert.NotNull(null);
            }
            catch (OneBlinkAPIException oneBlinkAPIException)
            {
                Assert.NotNull(oneBlinkAPIException);
                Assert.Equal(HttpStatusCode.Unauthorized, oneBlinkAPIException.StatusCode);
                Console.WriteLine(oneBlinkAPIException);
            }
        }
Пример #15
0
        public async void can_get_submission_data()
        {
            FormsClient             forms          = new FormsClient(ACCESS_KEY, SECRET_KEY, TenantName.ONEBLINK_TEST);
            FormSubmission <object> formSubmission = await forms.GetFormSubmission <object>(this.formId, this.submissionId);

            Assert.NotNull(formSubmission);
            if (formSubmission.device != null)
            {
                foreach (PropertyInfo propertyInfo in formSubmission.device.GetType().GetProperties())
                {
                    Console.WriteLine("Device: {0}={1}", propertyInfo.Name, propertyInfo.GetValue(formSubmission.device, null));
                }
            }
            if (formSubmission.user != null)
            {
                foreach (PropertyInfo propertyInfo in formSubmission.user.GetType().GetProperties())
                {
                    Console.WriteLine("User: {0}={1}", propertyInfo.Name, propertyInfo.GetValue(formSubmission.user, null));
                }
            }
        }
Пример #16
0
        public IActionResult PostForm(IFormCollection collection)
        {
            var path = HttpContext.Request.Path;

            var form = new FormSubmission();

            var recipient = collection
                            .TryGetValue("recipient", out var recipientValue);

            var redirect = collection.TryGetValue("redirect", out var redirectValue);

            if (!recipient || !redirect)
            {
                return(new BadRequestResult());
            }

            foreach (var keyValuePair in collection)
            {
                var key   = keyValuePair.Key;
                var value = keyValuePair.Value;
                form.AddToSubmissions(key, value);
            }

            form.Remove("recipient");
            form.Remove("redirect");

            var json = form.Return()
                       .Serialize();

            EmailService.Send(json, recipientValue);

            var data = new FormData()
            {
                SerializedData = json,
                CreatedAt      = DateTime.Now,
                UpdatedAt      = DateTime.Now
            };

            return(Redirect(redirectValue));
        }
Пример #17
0
        public async Task ProcessAsync(ACFormProcessor processor, FormEntry formEntry)
        {
            var mappings = JsonSerializer.Deserialize <Dictionary <string, string> >(processor.ConversionSpec);

            var formData = JsonSerializer.Deserialize <FormData>(formEntry.Data);


            _logger.LogInformation("Creating UiPath submission for FormEntry {formEntry}", formEntry.Id);
            formData.data.TryGetValue(mappings["CPTCodes"], out var cptCodes);
            formData.data.TryGetValue(mappings["DiagnosisCodes"], out var diagnosisCodes);
            formData.data.TryGetValue(mappings["MemberFirstName"], out var memberFirstName);
            formData.data.TryGetValue(mappings["MemberLastName"], out var memberLastName);
            formData.data.TryGetValue(mappings["NPIReferFrom"], out var npiReferFrom);
            formData.data.TryGetValue(mappings["NPIReferTo"], out var npiReferTo);
            formData.data.TryGetValue(mappings["MemberDOB"], out var memberDobStr);

            DateTime.TryParse(memberDobStr.ToString(), out var memberDob);
            var cpt  = JsonSerializer.Deserialize <List <string> >(cptCodes.ToString());
            var diag = JsonSerializer.Deserialize <List <string> >(diagnosisCodes.ToString());

            var submission = new FormSubmission
            {
                FormEntryId     = formEntry.Id,
                PDFPath         = $"{formEntry.Id}",
                CPTCodes        = string.Join(",", cpt),
                DiagnosisCodes  = string.Join(",", diag),
                MemberDOB       = memberDob,
                MemberFirstName = memberFirstName.ToString(),
                MemberLastName  = memberLastName.ToString(),
                NPIReferFrom    = npiReferFrom.ToString(),
                NPIReferTo      = npiReferTo.ToString(),
                SubmissionDate  = formEntry.SubmissionDate.GetValueOrDefault()
            };

            await _uiPathDb.AddAsync(submission);

            await _uiPathDb.SaveChangesAsync();

            _logger.LogInformation("UiPath submission for FormEntry {formEntry} successfully created", formEntry.Id);
        }
Пример #18
0
        public async void get_draft_data_should_throw_oneblink_exception()
        {
            FormsClient forms = new FormsClient(
                "123",
                "aaaaaaaaaaaaaaabbbbbbbbbbbbbbbcccccccccccccccc",
                tenantName: TenantName.ONEBLINK_TEST
                );

            try
            {
                FormSubmission <object> draftSubmission = await forms.GetFormSubmission <object>(this.draftFormId, this.draftDataId, true);

                Console.WriteLine("Submission as JSON string: " + draftSubmission.submission);
                Assert.NotNull(null);
            }
            catch (OneBlinkAPIException oneBlinkAPIException)
            {
                Assert.NotNull(oneBlinkAPIException);
                Assert.Equal(HttpStatusCode.Unauthorized, oneBlinkAPIException.StatusCode);
                Console.WriteLine(oneBlinkAPIException);
            }
        }
Пример #19
0
        public IActionResult PostForm(IFormCollection collection)
        {
            var form = new FormSubmission();

            var recipient = collection
                            .TryGetValue("recipient", out var recipientValue);

            var redirect = collection.TryGetValue("redirect", out var redirectValue);

            if (!recipient)
            {
                return(new BadRequestResult());
            }

            foreach (var keyValuePair in collection)
            {
                var key   = keyValuePair.Key;
                var value = keyValuePair.Value;
                form.AddToSubmissions(key, value);
            }

            form.Remove("recipient");
            form.Remove("redirect");

            var json = form.Return()
                       .Serialize();

            EmailService.Send(json, recipientValue);

            if (redirect)
            {
                return(Redirect(redirectValue));
            }

            throw new Exception("The redirect is required as a mandatory field.");
        }
Пример #20
0
        public List <FormSubmissionAnswer> ViewSubmissionAnswers(int FormDocumentID)
        {
            FormSubmissionAnswerDAC     _formSubmissionAnswerComponent = new FormSubmissionAnswerDAC();
            IDataReader                 reader = _formSubmissionAnswerComponent.ViewSubmissionAnswers("FormDocumentID = " + FormDocumentID).CreateDataReader();
            List <FormSubmissionAnswer> _formSubmissionAnswerList = new List <FormSubmissionAnswer>();

            while (reader.Read())
            {
                if (_formSubmissionAnswerList == null)
                {
                    _formSubmissionAnswerList = new List <FormSubmissionAnswer>();
                }
                FormSubmissionAnswer _formSubmissionAnswer = new FormSubmissionAnswer();
                #region FormSubmissionAnswer Fields
                if (reader["FormSubmissionAnswerId"] != DBNull.Value)
                {
                    _formSubmissionAnswer.FormSubmissionAnswerId = Convert.ToInt32(reader["FormSubmissionAnswerId"]);
                }
                if (reader["FormSubmissionId"] != DBNull.Value)
                {
                    _formSubmissionAnswer.FormSubmissionId = Convert.ToInt32(reader["FormSubmissionId"]);
                }
                if (reader["FormFieldId"] != DBNull.Value)
                {
                    _formSubmissionAnswer.FormFieldId = Convert.ToInt32(reader["FormFieldId"]);
                }
                if (reader["Answer"] != DBNull.Value)
                {
                    _formSubmissionAnswer.Answer = Convert.ToString(reader["Answer"]);
                }
                if (reader["FormFieldColumnId"] != DBNull.Value)
                {
                    _formSubmissionAnswer.FormFieldColumnId = Convert.ToInt32(reader["FormFieldColumnId"]);
                }
                if (reader["FormFieldValueId"] != DBNull.Value)
                {
                    _formSubmissionAnswer.FormFieldValueId = Convert.ToInt32(reader["FormFieldValueId"]);
                }
                if (reader["Grade"] != DBNull.Value)
                {
                    _formSubmissionAnswer.Grade = Convert.ToInt32(reader["Grade"]);
                }
                #endregion

                #region FormSubmission Fields
                FormSubmission _formSubmission = new FormSubmission();
                if (reader["FormSubmissionId"] != DBNull.Value)
                {
                    _formSubmission.FormSubmissionId = Convert.ToInt32(reader["FormSubmissionId"]);
                }
                if (reader["UserId"] != DBNull.Value)
                {
                    _formSubmission.UserId = Convert.ToInt32(reader["UserId"]);
                }
                if (reader["IsAnonymous"] != DBNull.Value)
                {
                    _formSubmission.IsAnonymous = Convert.ToBoolean(reader["IsAnonymous"]);
                }
                if (reader["SubmissionDate"] != DBNull.Value)
                {
                    _formSubmission.SubmissionDate = Convert.ToDateTime(reader["SubmissionDate"]);
                }
                if (reader["IPAddress"] != DBNull.Value)
                {
                    _formSubmission.IPAddress = Convert.ToString(reader["IPAddress"]);
                }
                if (reader["IsValid"] != DBNull.Value)
                {
                    _formSubmission.IsValid = Convert.ToBoolean(reader["IsValid"]);
                }
                if (reader["EmailSent"] != DBNull.Value)
                {
                    _formSubmission.EmailSent = Convert.ToBoolean(reader["EmailSent"]);
                }
                if (reader["SMSSent"] != DBNull.Value)
                {
                    _formSubmission.SMSSent = Convert.ToBoolean(reader["SMSSent"]);
                }
                if (reader["FormDocumentID"] != DBNull.Value)
                {
                    _formSubmission.FormDocumentID = Convert.ToInt32(reader["FormDocumentID"]);
                }
                _formSubmission.NewRecord = false;

                BusinessLogicLayer.Entities.Persons.Credential _credential = new Entities.Persons.Credential();
                if (reader["UserId"] != DBNull.Value)
                {
                    _credential.BusinessEntityId = Convert.ToInt32(reader["UserId"]);
                }
                if (reader["Username"] != DBNull.Value)
                {
                    _credential.Username = Convert.ToString(reader["Username"]);
                }
                _formSubmission.User = _credential;
                _formSubmissionAnswer.FormSubmission = _formSubmission;
                #endregion

                _formSubmissionAnswer.NewRecord = false;
                _formSubmissionAnswerList.Add(_formSubmissionAnswer);
            }
            reader.Close();
            return(_formSubmissionAnswerList);
        }
Пример #21
0
        public bool Update(FormSubmission formsubmission, int old_formSubmissionId)
        {
            FormSubmissionDAC formsubmissionComponent = new FormSubmissionDAC();

            return(formsubmissionComponent.UpdateFormSubmission(formsubmission.UserId, formsubmission.IsAnonymous, formsubmission.SubmissionDate, formsubmission.IPAddress, formsubmission.IsValid, formsubmission.EmailSent, formsubmission.SMSSent, formsubmission.FormDocumentID, old_formSubmissionId));
        }
Пример #22
0
        public async Task <Response> SubmitForm(int formId, Dictionary <string, string> submission)
        {
            var response = new Response();


            //get form we're creating a submission for
            var formEntity = await _formService.GetFormComplete(formId);


            //TODO: check origin from http headers with allowed origins from form

            //TODO: validate all fields here
            formEntity.Fields.ToList().ForEach(field =>
            {
                //basic rules
                if (field.Validation.Type == ValidationType.Rules)
                {
                    var required = field.Validation.Rules.FirstOrDefault(r => r.FormFieldValidationRuleTypeId == (int)RuleType.Required) != null;

                    if (field.FormFieldTypeId != (int)FieldType.CheckBox)
                    {
                        var submittedValue = submission.GetValueOrDefault(field.Name);

                        //universal rule
                        if ((submittedValue == null || String.IsNullOrWhiteSpace(submittedValue)) && required)
                        {
                            response.AddError(field.Name, "Required");
                        }

                        if (submittedValue != null)
                        {
                            //specific rules based on field type
                            switch (field.FormFieldTypeId)
                            {
                            case (int)FieldType.Number:

                                bool isNumber = double.TryParse(submittedValue, out double parsedValue);
                                var minRule   = field.Validation.Rules.FirstOrDefault(r => r.FormFieldValidationRuleTypeId == (double)RuleType.Minimum_Value);
                                var maxRule   = field.Validation.Rules.FirstOrDefault(r => r.FormFieldValidationRuleTypeId == (double)RuleType.Maxmimum__Value);
                                if (!isNumber)
                                {
                                    response.AddError(field.Name, "Value must be a number");
                                }
                                else
                                {
                                    if (minRule != null && parsedValue < double.Parse(minRule.Constraint))
                                    {
                                        response.AddError(field.Name, "Value must be greater than or equal to " + minRule.Constraint);
                                    }
                                    else if (maxRule != null && parsedValue > double.Parse(maxRule.Constraint))
                                    {
                                        response.AddError(field.Name, "Value must be less than or equal to " + maxRule.Constraint);
                                    }
                                }
                                break;

                            case (int)FieldType.String:

                                var minLengthRule = field.Validation.Rules.FirstOrDefault(r => r.FormFieldValidationRuleTypeId == (int)RuleType.Minimum_Length);
                                var maxLengthRule = field.Validation.Rules.FirstOrDefault(r => r.FormFieldValidationRuleTypeId == (int)RuleType.Maxmimum_Length);
                                if (minLengthRule != null && submittedValue.Length < int.Parse(minLengthRule.Constraint))
                                {
                                    response.AddError(field.Name, "Value must be at least " + minLengthRule.Constraint + " characters long");
                                }
                                else if (maxLengthRule != null && submittedValue.Length > int.Parse(maxLengthRule.Constraint))
                                {
                                    response.AddError(field.Name, "Value must be less than or equal to " + maxLengthRule.Constraint + " characters long");
                                }
                                break;

                            case (int)FieldType.Date:
                                bool isDate     = DateTime.TryParse(submittedValue, out DateTime parsedDate);
                                var minDateRule = field.Validation.Rules.FirstOrDefault(r => r.FormFieldValidationRuleTypeId == (int)RuleType.Minimum_Date);
                                var maxDateRule = field.Validation.Rules.FirstOrDefault(r => r.FormFieldValidationRuleTypeId == (int)RuleType.Maxmimum_Date);
                                if (!isDate)
                                {
                                    response.AddError(field.Name, "Value must be a date");
                                }
                                else
                                {
                                    if (minDateRule != null && parsedDate < DateTime.Parse(minDateRule.Constraint))
                                    {
                                        response.AddError(field.Name, "Date must be after " + minDateRule.Constraint);
                                    }
                                    else if (maxDateRule != null && parsedDate > DateTime.Parse(maxDateRule.Constraint))
                                    {
                                        response.AddError(field.Name, "Date must be before " + maxDateRule.Constraint);
                                    }
                                }
                                break;

                            case (int)FieldType.RadioButton:
                            case (int)FieldType.DropDown:
                                if (submission.ContainsKey(field.Name))
                                {
                                    //make sure submitted value is one of the possible options provided
                                    var selectedValue = field.Options.FirstOrDefault(o => o.Value == submission[field.Name]);
                                    if (selectedValue == null)
                                    {
                                        response.AddError(field.Name, "Invalid value selected");
                                    }
                                }
                                break;
                            }
                        }
                    }
                    else
                    {
                        int selectedOptions = 0;

                        //check boxes have special naming conventions for values
                        foreach (FormFieldOption option in field.Options)
                        {
                            if (submission.ContainsKey(field.Name + "-" + option.Value))
                            {
                                selectedOptions++;
                            }
                        }

                        if (selectedOptions == 0 && required)
                        {
                            response.AddError(field.Name, "Required");
                        }
                    }
                }
                //custom javascript validation
                else if (field.Validation.Type == ValidationType.CustomScript)
                {
                }
            });

            if (response.Errors.Count == 0)
            {
                //create a new submission entity
                var submissionEntity = new FormSubmission()
                {
                    CreatedOn = DateTime.UtcNow
                };

                //add submission values to entity and map the fields
                formEntity.Fields.ToList().ForEach(field =>
                {
                    //check boxes can have multiple submission values for one field
                    if (field.FormFieldType.FormFieldTypeId == (int)FieldType.CheckBox)
                    {
                        foreach (FormFieldOption option in field.Options)
                        {
                            if (submission.ContainsKey(field.Name + "-" + option.Value))
                            {
                                submissionEntity.Values.Add(new FormSubmissionValue()
                                {
                                    Field = field,
                                    Value = option.Value
                                });
                            }
                        }
                    }
                    else if (submission.ContainsKey(field.Name))
                    {
                        submissionEntity.Values.Add(new FormSubmissionValue()
                        {
                            Field = field,
                            Value = submission[field.Name]
                        });
                    }
                });

                formEntity.Submissions.Add(submissionEntity);

                await _dbContext.SaveChangesAsync();

                response.Success = true;
            }

            return(response);
        }