Example #1
0
        public ActionResult AddForm()
        {
            ViewBag.AccountId = this.Identity.ToAccountID();
            GetAllContactFieldsRequest  request  = new GetAllContactFieldsRequest();
            GetAllContactFieldsResponse response = formService.GetAllContactFields(request);
            var fieldsToBeRemoved = new List <int>();

            fieldsToBeRemoved.Add((int)ContactFields.PartnerTypeField);
            fieldsToBeRemoved.Add((int)ContactFields.DonotEmail);
            fieldsToBeRemoved.Add((int)ContactFields.LifecycleStageField);
            fieldsToBeRemoved.Add((int)ContactFields.LeadScore);
            fieldsToBeRemoved.Add((int)ContactFields.Owner);
            fieldsToBeRemoved.Add((int)ContactFields.WebPage);
            fieldsToBeRemoved.Add((int)ContactFields.WebPageDuration);
            fieldsToBeRemoved.Add((int)ContactFields.ContactTag);
            fieldsToBeRemoved.Add((int)ContactFields.FormName);
            fieldsToBeRemoved.Add((int)ContactFields.FormsubmittedOn);
            fieldsToBeRemoved.Add((int)ContactFields.FirstSourceType);
            fieldsToBeRemoved.Add((int)ContactFields.NoteSummary);
            fieldsToBeRemoved.Add((int)ContactFields.LastNoteDate);
            FormViewModel formViewModel = new FormViewModel();

            formViewModel.Fields     = response.ContactFields.Where(c => !fieldsToBeRemoved.Contains(c.FieldId)).ToList();
            formViewModel.FormFields = new List <FormFieldViewModel>();
            FieldViewModel firstNameField    = formViewModel.Fields.Where(f => f.FieldId == (int)ContactFields.FirstNameField).FirstOrDefault();
            FieldViewModel lastNameField     = formViewModel.Fields.Where(f => f.FieldId == (int)ContactFields.LastNameField).FirstOrDefault();
            FieldViewModel primaryEmailField = formViewModel.Fields.Where(f => f.FieldId == (int)ContactFields.PrimaryEmail).FirstOrDefault();
            FieldViewModel mobilePhoneField  = formViewModel.Fields.Where(f => f.FieldId == (int)ContactFields.MobilePhoneField).FirstOrDefault();
            FieldViewModel leadSourceField   = formViewModel.Fields.Where(f => f.FieldId == (int)ContactFields.LeadSource).FirstOrDefault();
            var            communityField    = formViewModel.Fields.Where(c => c.FieldId == (int)ContactFields.Community).FirstOrDefault();

            communityField.FieldInputTypeId = FieldType.dropdown;
            formViewModel.FormFields.Add(new FormFieldViewModel()
            {
                DisplayName      = firstNameField.Title,
                FieldId          = firstNameField.FieldId,
                FieldInputTypeId = firstNameField.FieldInputTypeId,
                IsMandatory      = firstNameField.IsMandatory,
                StatusId         = firstNameField.StatusId,
                Title            = firstNameField.Title,
                Value            = firstNameField.Value,
                ValueOptions     = firstNameField.ValueOptions
            });
            formViewModel.FormFields.Add(new FormFieldViewModel()
            {
                DisplayName      = lastNameField.Title,
                FieldId          = lastNameField.FieldId,
                FieldInputTypeId = lastNameField.FieldInputTypeId,
                IsMandatory      = lastNameField.IsMandatory,
                StatusId         = lastNameField.StatusId,
                Title            = lastNameField.Title,
                Value            = lastNameField.Value,
                ValueOptions     = lastNameField.ValueOptions
            });
            formViewModel.FormFields.Add(new FormFieldViewModel()
            {
                DisplayName      = primaryEmailField.Title,
                FieldId          = primaryEmailField.FieldId,
                FieldInputTypeId = primaryEmailField.FieldInputTypeId,
                IsMandatory      = true,
                StatusId         = primaryEmailField.StatusId,
                Title            = primaryEmailField.Title,
                Value            = primaryEmailField.Value,
                ValueOptions     = primaryEmailField.ValueOptions
            });
            formViewModel.FormFields.Add(new FormFieldViewModel()
            {
                DisplayName      = mobilePhoneField.Title,
                FieldId          = mobilePhoneField.FieldId,
                FieldInputTypeId = mobilePhoneField.FieldInputTypeId,
                IsMandatory      = false,
                StatusId         = mobilePhoneField.StatusId,
                Title            = mobilePhoneField.Title,
                Value            = mobilePhoneField.Value,
                ValueOptions     = mobilePhoneField.ValueOptions
            });
            formViewModel.FormFields.Add(new FormFieldViewModel()
            {
                DisplayName      = leadSourceField.Title,
                FieldId          = leadSourceField.FieldId,
                FieldInputTypeId = leadSourceField.FieldInputTypeId,
                IsMandatory      = true,
                StatusId         = leadSourceField.StatusId,
                Title            = leadSourceField.Title,
                Value            = leadSourceField.Value
            });
            //formViewModel.FormFields.Add(new FormFieldViewModel()
            //{
            //    DisplayName = "",
            //    FieldId = (int)ContactFields.FormURLField,
            //    FieldInputTypeId = FieldType.text,
            //    IsMandatory = false,
            //    StatusId = FieldStatus.Active,
            //    Title = "redirect-override",
            //    Value = null
            //});
            GetAllCustomFieldsRequest  customFieldRequest  = new GetAllCustomFieldsRequest(this.Identity.ToAccountID());
            GetAllCustomFieldsResponse customFieldResponse = customFieldService.GetAllCustomFieldsForForms(customFieldRequest);

            formViewModel.CustomFields        = customFieldResponse.CustomFields.Where(c => c.StatusId == FieldStatus.Active).ToList();
            formViewModel.FormId              = 0;
            formViewModel.Name                = "";
            formViewModel.Status              = Entities.FormStatus.Active;
            formViewModel.AcknowledgementType = Entities.AcknowledgementType.Url;
            formViewModel.CreatedBy           = this.Identity.ToUserID();
            formViewModel.LastModifiedBy      = this.Identity.ToUserID();
            formViewModel.AccountId           = this.Identity.ToAccountID();
            ViewBag.TagPopup = true;
            return(View("AddForm", formViewModel));
        }