public static async Task <(ChangedFields changed, string last)> ManageRecordAsync(UnanetClient una, p_PersonAccess1 s, Action <p_PersonAccess1> bespoke = null)
        {
            var _ = new ChangedFields(ManageFlags.PersonAccessChanged);

            bespoke?.Invoke(s);
            if (ManageRecordBase(null, s.XCF, 1, out var cf, out var add, out var last2))
            {
                return(_.Changed(), last2);
            }
            if (add)
            {
                return(_, "key field missing, please check export critieria");
            }
            var(r, last) = await una.SubmitSubManageAsync("0", HttpMethod.Get, "people/orgaccess/edit", null,
                                                          $"personkey={s.usernameKey}&oapkey={s.key}", null,
                                                          (z, f) =>
            {
                // cache template
                if (DateTime.Now > FormExpires || FormOptions == null || FormOrgTreesByName == null)
                {
                    f.Values["personkey"] = f.Values["oapkey"] = null;
                    FormExpires           = DateTime.Now.AddHours(3);
                    FormOptions           = new HtmlFormOptions
                    {
                        FormTemplate = new HtmlFormTemplate(f)
                    };
                    FormOrgTreesByName = BuildOrgTreesByName(z);
                }
                if (!cf.Contains("oa"))
                {
                    throw new ArgumentOutOfRangeException(nameof(cf));
                }
                //
                f.Values["personkey"] = s.usernameKey;
                f.Values["oapkey"]    = s.key;
                var org_access        = _._(s.org_access, nameof(s.org_access));
                switch (org_access)
                {
                case "!ALL!": f.FromSelectByKey("orgaccess", "all"); break;

                case "!NONE!": f.FromSelectByKey("orgaccess", "none"); break;

                default:
                    f.FromSelectByKey("orgaccess", "org");
                    var orgTreeKeys = org_access.Split(',').Select(x => FormOrgTreesByName[x.Trim()]).ToArray();
                    f.FromMultiCheckbox("orgTree_selected", orgTreeKeys);
                    break;
                }
                return(f.ToString());
            }, formOptions : FormOptions).ConfigureAwait(false);

            return(_.Changed(r), last);
        }
Beispiel #2
0
        public IHtmlContent CreateFormElement(IHtmlHelper htmlHelper, HtmlFormOptions options)
        {
            var             formGenerator = new HtmlFormGenerator(options);
            HtmlNodeElement formElement   = formGenerator.GenerateFormElement();

            AspValidationInjector aspValidationInjector = new AspValidationInjector(htmlHelper, options.FormValidationOptions);

            if (htmlHelper.ViewContext.ClientValidationEnabled)
            {
                aspValidationInjector.Inject(formElement);
            }

            return(HtmlBuilder.CreateHtmlContent(formElement));
        }
 internal HtmlFormGenerator(HtmlFormOptions options)
 {
     _options = options;
 }
        public static IHtmlContent FormFor <TModel, TResult>(this IHtmlHelper <TModel> htmlHelper, Expression <Func <TModel, TResult> > expression, HtmlFormOptions options = null)
        {
            options       = options ?? new HtmlFormOptions();
            options.Model = expression.Compile().Invoke(htmlHelper.ViewData.Model);

            return(htmlFactory.CreateFormElement(htmlHelper, options));
        }
 public static IHtmlContent Form(this IHtmlHelper htmlHelper, HtmlFormOptions options)
 {
     return(htmlFactory.CreateFormElement(htmlHelper, options));
 }