Beispiel #1
0
        public async Task <JsonResult> GetSystemForms()
        {
            // get all of the forms.
            var systemForms = await _system.Systemforms.ExecuteAsync();

            List <ViewModels.Form> forms = new List <ViewModels.Form>();

            foreach (var systemForm in systemForms)
            {
                ViewModels.Form form = new ViewModels.Form();
                form.name = systemForm.Name;
                form.id   = systemForm.Formidunique == null ? "" : systemForm.Formidunique.ToString();

                //adxForm.Adx_entityformid == null ? "" : adxForm.Adx_entityformid.ToString();
                //form.displayname = adxForm.Adx_formname;
                //form.entity = adxForm.Adx_entityname;
                form.entity = systemForm.Objecttypecode;
                // get the form fields.
                string key = "SystemForm_FormXML_" + form.entity;
                form.formxml = systemForm.Formxml;

                forms.Add(form);
            }
            return(Json(forms));
        }
Beispiel #2
0
        public async Task <ViewModels.Form> Update(ViewModels.Form form)
        {
            var newForm = await _repository.Create(_mapper.Map <ViewModels.Form, DAL.Entities.Form>(form));

            if (newForm == null)
            {
                return(null);
            }
            return(_mapper.Map <DAL.Entities.Form, ViewModels.Form>(newForm));
        }
        public async Task <IActionResult> GetSystemForm(string id)
        {
            ViewModels.Form form         = null;
            Guid?           systemformid = new Guid(id);

            Interfaces.Microsoft.Dynamics.CRM.Systemform systemform = null;
            if (id != null)
            {
                try
                {
                    systemform = await _system.Systemforms.ByKey(systemformid).GetValueAsync();

                    form         = new ViewModels.Form();
                    form.id      = id;
                    form.entity  = systemform.Objecttypecode;
                    form.name    = systemform.Name;
                    form.formxml = systemform.Formxml;
                    form.tabs    = new List <ViewModels.FormTab>();

                    var tabs = XDocument.Parse(form.formxml).XPathSelectElements("form/tabs/tab");
                    if (tabs != null)
                    {
                        foreach (var tab in tabs)
                        {
                            var     tabLabel     = tab.XPathSelectElement("labels/label");
                            string  description  = tabLabel.Attribute("description").Value;
                            string  tabId        = tabLabel.Attribute("id") == null ? "" : tabLabel.Attribute("id").Value;
                            Boolean tabShowLabel = tab.Attribute("showlabel").DynamicsAttributeToBoolean();
                            Boolean tabVisible   = tab.Attribute("visible").DynamicsAttributeToBoolean();

                            FormTab formTab = new FormTab();
                            formTab.id        = tabId;
                            formTab.name      = description;
                            formTab.sections  = new List <FormSection>();
                            formTab.showlabel = tabShowLabel;
                            formTab.visible   = tabVisible;

                            // get the sections
                            var sections = tab.XPathSelectElements("columns/column/sections/section");
                            foreach (var section in sections)
                            {
                                Boolean sectionShowLabel = section.Attribute("showlabel").DynamicsAttributeToBoolean();
                                Boolean sectionVisible   = section.Attribute("visible").DynamicsAttributeToBoolean();

                                FormSection formSection = new FormSection();
                                formSection.fields    = new List <FormField>();
                                formSection.id        = section.Attribute("id").Value;
                                formSection.showlabel = sectionShowLabel;
                                formSection.visible   = sectionVisible;

                                // get the fields.
                                var sectionLabels = section.XPathSelectElements("labels/label");

                                // the section label is the section name.
                                foreach (var sectionLabel in sectionLabels)
                                {
                                    formSection.name = sectionLabel.Attribute("description").Value;
                                }
                                // get the cells.
                                var cells = section.XPathSelectElements("rows/row/cell");

                                foreach (var cell in cells)
                                {
                                    FormField formField = new FormField();
                                    // get cell visibility and showlabel
                                    Boolean cellShowLabel = cell.Attribute("showlabel").DynamicsAttributeToBoolean();
                                    Boolean cellVisible   = cell.Attribute("visible").DynamicsAttributeToBoolean();


                                    formField.showlabel = cellShowLabel;
                                    formField.visible   = cellVisible;

                                    // get the cell label.


                                    var cellLabels = cell.XPathSelectElements("labels/label");
                                    foreach (var cellLabel in cellLabels)
                                    {
                                        formField.name = cellLabel.Attribute("description").Value;
                                    }
                                    // get the form field name.
                                    var control = cell.XPathSelectElement("control");
                                    if (!string.IsNullOrEmpty(formField.name) && control != null && control.Attribute("datafieldname") != null)
                                    {
                                        // datafieldname has to be translated.
                                        string originalFieldName = control.Attribute("datafieldname").Value;
                                        formField.datafieldname = TranslateDatafieldname(form.entity, originalFieldName);
                                        if (formField.datafieldname != null)
                                        {
                                            formField.classid     = control.Attribute("classid").Value;
                                            formField.controltype = formField.classid.DynamicsControlClassidToName();
                                            formField.required    = control.Attribute("isrequired").DynamicsAttributeToBoolean();
                                            // special case for picklists.
                                            if (formField.controltype != null && formField.controltype.Equals("PicklistControl"))
                                            {
                                                // get the options for the picklist and add it to the field.
                                                List <ViewModels.OptionMetadata> options = await _system.GetPicklistOptions(_distributedCache, originalFieldName);

                                                formField.options = options;
                                            }

                                            formSection.fields.Add(formField);
                                        }
                                    }
                                }

                                formTab.sections.Add(formSection);
                            }

                            form.tabs.Add(formTab);
                        }
                    }
                    else // single tab form.
                    {
                        FormTab formTab = new FormTab();
                        formTab.name = "";
                        form.tabs.Add(formTab);
                    }
                }
                catch (Microsoft.OData.Client.DataServiceQueryException dsqe)
                {
                    return(new NotFoundResult());
                }
            }



            return(Json(form));
        }
Beispiel #4
0
        public async Task <JsonResult> GetSystemForm(string id)
        {
            string entityKey = "SystemForm_" + id + "_Entity";
            string nameKey   = "SystemForm_" + id + "_Name";
            string xmlKey    = "SystemForm_" + id + "_FormXML";
            string formXml   = await _distributedCache.GetStringAsync(xmlKey);

            ViewModels.Form form = new ViewModels.Form();
            form.id     = id;
            form.entity = await _distributedCache.GetStringAsync(entityKey);

            form.name = await _distributedCache.GetStringAsync(nameKey);

            form.formxml = formXml;
            form.tabs    = new List <ViewModels.FormTab>();

            var tabs = XDocument.Parse(formXml).XPathSelectElements("form/tabs/tab");

            if (tabs != null)
            {
                foreach (var tab in tabs)
                {
                    var     tabLabel     = tab.XPathSelectElement("labels/label");
                    string  description  = tabLabel.Attribute("description").Value;
                    string  tabId        = tabLabel.Attribute("id") == null ? "" : tabLabel.Attribute("id").Value;
                    Boolean tabShowLabel = tab.Attribute("showlabel").DynamicsAttributeToBoolean();
                    Boolean tabVisible   = tab.Attribute("visible").DynamicsAttributeToBoolean();

                    FormTab formTab = new FormTab();
                    formTab.id        = tabId;
                    formTab.name      = description;
                    formTab.sections  = new List <FormSection>();
                    formTab.showlabel = tabShowLabel;
                    formTab.visible   = tabVisible;

                    // get the sections
                    var sections = tab.XPathSelectElements("columns/column/sections/section");
                    foreach (var section in sections)
                    {
                        Boolean sectionShowLabel = section.Attribute("showlabel").DynamicsAttributeToBoolean();
                        Boolean sectionVisible   = section.Attribute("visible").DynamicsAttributeToBoolean();

                        FormSection formSection = new FormSection();
                        formSection.fields    = new List <FormField>();
                        formSection.id        = section.Attribute("id").Value;
                        formSection.showlabel = sectionShowLabel;
                        formSection.visible   = sectionVisible;

                        // get the fields.
                        var sectionLabels = section.XPathSelectElements("labels/label");

                        // the section label is the section name.
                        foreach (var sectionLabel in sectionLabels)
                        {
                            formSection.name = sectionLabel.Attribute("description").Value;
                        }
                        // get the cells.
                        var cells = section.XPathSelectElements("rows/row/cell");

                        foreach (var cell in cells)
                        {
                            FormField formField = new FormField();
                            // get cell visibility and showlabel
                            Boolean cellShowLabel = cell.Attribute("showlabel").DynamicsAttributeToBoolean();
                            Boolean cellVisible   = cell.Attribute("visible").DynamicsAttributeToBoolean();


                            formField.showlabel = cellShowLabel;
                            formField.visible   = cellVisible;

                            // get the cell label.


                            var cellLabels = cell.XPathSelectElements("labels/label");
                            foreach (var cellLabel in cellLabels)
                            {
                                formField.name = cellLabel.Attribute("description").Value;
                            }
                            // get the form field name.
                            var control = cell.XPathSelectElement("control");
                            if (!string.IsNullOrEmpty(formField.name) && control != null && control.Attribute("datafieldname") != null)
                            {
                                formField.classid       = control.Attribute("classid").Value;
                                formField.controltype   = formField.classid.DynamicsControlClassidToName();
                                formField.datafieldname = control.Attribute("datafieldname").Value;
                                formField.required      = control.Attribute("isrequired").DynamicsAttributeToBoolean();
                                formSection.fields.Add(formField);
                            }
                        }

                        formTab.sections.Add(formSection);
                    }

                    form.tabs.Add(formTab);
                }
            }
            else // single tab form.
            {
                FormTab formTab = new FormTab();
                formTab.name = "";
                form.tabs.Add(formTab);
            }

            return(Json(form));
        }
Beispiel #5
0
        public async Task <JsonResult> GetSystemForm(string formid)
        {
            // get the picklists.

            List <MicrosoftDynamicsCRMpicklistAttributeMetadata> picklistMetadata = null;

            try
            {
                picklistMetadata = _dynamicsClient.Entitydefinitions.GetEntityPicklists("adoxio_application").Value;
            }
            catch (Exception e)
            {
                _logger.LogError(e, "ERROR getting accounts picklist metadata");
            }

            // get the application mapping.

            ApplicationMapping applicationMapping = new ApplicationMapping();
            var systemForm = _dynamicsClient.Systemforms.GetByKey(formid);

            /*
             * string entityKey = "SystemForm_" + id + "_Entity";
             * string nameKey = "SystemForm_" + id + "_Name";
             * string xmlKey = "SystemForm_" + id + "_FormXML";
             * string formXml = await _distributedCache.GetStringAsync(xmlKey);
             */

            string formXml = systemForm.Formxml;

            ViewModels.Form form = new ViewModels.Form();
            form.id       = formid;
            form.tabs     = new List <ViewModels.FormTab>();
            form.sections = new List <ViewModels.FormSection>();

            var tabs = XDocument.Parse(formXml).XPathSelectElements("form/tabs/tab");

            if (tabs != null)
            {
                foreach (var tab in tabs)
                {
                    var     tabLabel     = tab.XPathSelectElement("labels/label");
                    string  description  = tabLabel.Attribute("description").Value;
                    string  tabId        = tabLabel.Attribute("id") == null ? "" : tabLabel.Attribute("id").Value;
                    Boolean tabShowLabel = tab.Attribute("showlabel").DynamicsAttributeToBoolean();
                    Boolean tabVisible   = tab.Attribute("visible").DynamicsAttributeToBoolean();

                    FormTab formTab = new FormTab();
                    formTab.id        = tabId;
                    formTab.name      = description;
                    formTab.sections  = new List <FormSection>();
                    formTab.showlabel = tabShowLabel;
                    formTab.visible   = tabVisible;

                    // get the sections
                    var sections = tab.XPathSelectElements("columns/column/sections/section");
                    foreach (var section in sections)
                    {
                        Boolean sectionShowLabel = section.Attribute("showlabel").DynamicsAttributeToBoolean();
                        Boolean sectionVisible   = section.Attribute("visible").DynamicsAttributeToBoolean();
                        if (section.Attribute("visible") == null)
                        {
                            sectionVisible = true; // default visibility to true if it is not specified.
                        }


                        FormSection formSection = new FormSection();
                        formSection.fields    = new List <FormField>();
                        formSection.id        = section.Attribute("id").Value;
                        formSection.showlabel = sectionShowLabel;
                        formSection.visible   = sectionVisible;

                        // get the fields.
                        var sectionLabels = section.XPathSelectElements("labels/label");

                        // the section label is the section name.
                        foreach (var sectionLabel in sectionLabels)
                        {
                            formSection.name = sectionLabel.Attribute("description").Value;
                        }
                        // get the cells.
                        var cells = section.XPathSelectElements("rows/row/cell");

                        foreach (var cell in cells)
                        {
                            FormField formField = new FormField();
                            // get cell visibility and showlabel
                            bool cellShowLabel = cell.Attribute("showlabel").DynamicsAttributeToBoolean();
                            bool cellVisible   = cell.Attribute("visible").DynamicsAttributeToBoolean();

                            // set the cell to visible if it is not hidden.
                            if (cell.Attribute("visible") == null)
                            {
                                cellVisible = true;
                            }

                            formField.showlabel = cellShowLabel;
                            formField.visible   = cellVisible;

                            // get the cell label.

                            if (formField.showlabel)
                            {
                                var cellLabels = cell.XPathSelectElements("labels/label");
                                foreach (var cellLabel in cellLabels)
                                {
                                    formField.name = cellLabel.Attribute("description").Value;
                                }
                            }
                            else
                            {
                                // use the section name.
                                formField.name   = formSection.name;
                                formSection.name = "";
                            }


                            // get the form field name.
                            var control = cell.XPathSelectElement("control");
                            if (!string.IsNullOrEmpty(formField.name) && control != null && control.Attribute("datafieldname") != null)
                            {
                                formField.classid     = control.Attribute("classid").Value;
                                formField.controltype = formField.classid.DynamicsControlClassidToName();
                                string datafieldname = control.Attribute("datafieldname").Value;
                                // translate the data field name
                                formField.datafieldname = applicationMapping.GetViewModelKey(datafieldname);

                                formField.required = control.Attribute("isrequired").DynamicsAttributeToBoolean();

                                if (formField.controltype.Equals("PicklistControl"))
                                {
                                    // get the options.
                                    var metadata = picklistMetadata.FirstOrDefault(x => x.LogicalName == datafieldname);

                                    formField.options = new List <OptionMetadata>();

                                    if (metadata == null)
                                    {
                                        formField.options.Add(new OptionMetadata()
                                        {
                                            label = "INVALID PICKLIST", value = 0
                                        });
                                    }
                                    else
                                    {
                                        MicrosoftDynamicsCRMoptionSet optionSet = null;
                                        // could be an OptionSet or a globalOptionSet.
                                        if (metadata.OptionSet != null)
                                        {
                                            optionSet = metadata.OptionSet;
                                        }
                                        else
                                        {
                                            optionSet = metadata.GlobalOptionSet;
                                        }
                                        if (optionSet != null)
                                        {
                                            foreach (var option in optionSet.Options)
                                            {
                                                int?   value = option.Value;
                                                string label = option.Label?.UserLocalizedLabel?.Label;
                                                if (value == null || label == null)
                                                {
                                                    formField.options.Add(new OptionMetadata()
                                                    {
                                                        label = "INVALID PICKLIST", value = 0
                                                    });
                                                }
                                                else
                                                {
                                                    formField.options.Add(new OptionMetadata()
                                                    {
                                                        label = label, value = value.Value
                                                    });
                                                }
                                            }
                                        }
                                    }
                                }
                                if (formField.datafieldname != null)
                                {
                                    formSection.fields.Add(formField);
                                }
                            }
                        }

                        formTab.sections.Add(formSection);
                        form.sections.Add(formSection);
                    }

                    form.tabs.Add(formTab);
                }
            }
            else // single tab form.
            {
                FormTab formTab = new FormTab();
                formTab.name = "";
                form.tabs.Add(formTab);
            }

            return(new JsonResult(form));
        }