示例#1
0
        public ActionResult EditKnockoutJS(User user)
        {
            FormResponseData responseData = new FormResponseData()
            {
                Success = false
            };

            if (this.ModelState.IsValid)
            {
                CurrentUser          = user;
                responseData.Success = true;
            }

            return(Json(responseData));
        }
        public async Task <bool> Form_Submit(Guid faction_id, Guid form_id)
        {
            HavenSDK sdk = this.GetHavenSDK(faction_id);

            FactionPublic faction = _account.factions_member.FirstOrDefault(x => x.faction_id == faction_id);

            List <Form> forms = await sdk.Forms.GetForFactionAccount(faction_id, true, true, null, 0, 20).DemoUnPack();

            Form form = forms.FirstOrDefault(x => x.form_id == form_id);

            if (form == null)
            {
                throw new Exception("Check demonstration code for proper IDs");
            }

            FormResponse response = new FormResponse()
            {
                account_id   = _account.account_id, // can be different than current user if admin
                form_id      = form.form_id,
                faction_id   = form.faction_id,
                member_id    = form.attachment == FormAttachmentType.Member ? faction.member_id.GetValueOrDefault() : (Guid?)null,       // Required if FormAttachmentType.Member
                principal_id = form.attachment == FormAttachmentType.Principal ? faction.principal_id.GetValueOrDefault() : (Guid?)null, // Required if FormAttachmentType.Principal
            };

            response.response_data = new List <FormResponseData>();
            foreach (FormSection section in form.sections.Where(x => x.kind == FormSectionKind.form_question))
            {
                FormResponseData data = new FormResponseData()
                {
                    form_question_id = section.question.form_question_id
                };
                switch (section.question.config.kind)
                {
                case FormOptionKind.Text:
                    data.response_raw     = "Answered";
                    data.response_display = "Answered";
                    break;

                case FormOptionKind.Date:
                    data.response_raw     = DateTime.UtcNow.ToString();
                    data.response_display = data.response_raw;
                    break;

                case FormOptionKind.Number:
                    data.response_raw     = "134";
                    data.response_display = "134";
                    break;

                case FormOptionKind.SingleChoice:
                    ValuePair singleOption = section.question.config.options.FirstOrDefault();
                    data.response_raw     = singleOption.value;
                    data.response_display = singleOption.name;
                    break;

                case FormOptionKind.MultipleChoice:
                    ValuePair option = section.question.config.options.FirstOrDefault();
                    data.response_raw     = option.value;
                    data.response_display = option.name;
                    break;

                case FormOptionKind.Email:
                    data.response_raw     = "*****@*****.**";
                    data.response_display = "*****@*****.**";
                    break;

                case FormOptionKind.PhotoUpload:
                    //TODO: Photo Upload Sample
                    // uploadUrl = sdk.Media.GetTemporaryUploadUrl();
                    // upload to URL
                    break;

                default:
                    break;
                }
                response.response_data.Add(data);
            }
            ActionResult result = await sdk.Forms.SubmitFormAsync(response);

            return(result.IsSuccess());
        }