예제 #1
0
        public async Task <ActionResult> WebFormGenerator(ViewMetadataModel model)
        {
            List <WebFormModel> webFormElements = new List <WebFormModel>();

            //Se o modelo de dados for nulo, logo estamos perante um caso de pedido inválido (Bad Request)
            if (model == null)
            {
                return(BadRequest());
            }

            if (model.Branch == null)
            {
                return(await Task.Run(() => Redirect("/Metadata/SelectBranch?processId=" + model.Id + "&processName=" + model.Name + "&processVersion=" + model.Version + "&processDate=" + model.Date + "&processBranches=" + model.Branch + "&processState=" + model.State + "&isReadonly='true'")));
            }

            //Valores para preenchimento de campos hidden no formulário gerado automaticamente;
            ViewBag.ObjectId       = null;
            ViewBag.ProcessId      = model.Id;
            ViewBag.ProcessVersion = model.Version;
            ViewBag.ProcessBranch  = model.Branch;

            string ProcessFields = string.Empty;

            _Connection.DatabaseConnection();

            //Chamadas aos serviços - Ligação à base de dados
            _Metadata.SetDatabase(_Connection.GetDatabase());
            _Field.SetDatabase(_Connection.GetDatabase());
            _Properties.SetDatabase(_Connection.GetDatabase());
            _Data.SetDatabase(_Connection.GetDatabase());

            List <string> fields = _Metadata.GetProcessFieldsID(model.Id); //Obter os campos existentes no processo seleccionado;

            for (int j = 0; j < fields.Count; j++)
            {
                FieldModel fieldModel = _Field.GetField(fields.ElementAt(j));

                if (j == fields.Count - 1)
                {
                    ProcessFields += fieldModel.Type;
                }
                else
                {
                    ProcessFields += fieldModel.Type + " ";
                }

                PropertiesModel propertiesModel = _Properties.GetProperties(fieldModel.Properties);

                WebFormModel webFormElement = new WebFormModel()
                {
                    Type      = fieldModel.Type,
                    Name      = fieldModel.Name,
                    Size      = propertiesModel.Size.ToString(),
                    Value     = string.Empty,
                    Maxlength = propertiesModel.Maxlength.ToString(),
                    Required  = propertiesModel.Required.ToString(),
                    Readonly  = model.State.Equals("true") ? true : false
                };

                webFormElements.Add(webFormElement);
            }

            ViewBag.Readonly = model.State.Equals("true") ? "true" : "false";

            //Passar a lista de webform elements a uma classe que vai criar uma array com as linhas a serem renderizadas;
            WebFormTemplate webFormTemplate = new WebFormTemplate(webFormElements);
            List <string>   fragments       = webFormTemplate.Template();

            string template = string.Empty;

            for (int j = 0; j < fragments.Count; j++)
            {
                if (j == fragments.Count - 1)
                {
                    template += fragments[j];
                }
                else
                {
                    template += (fragments[j] + "|");
                }
            }

            ViewBag.Template = template;

            return(await Task.Run(() => View("WebFormGenerator")));
        }
예제 #2
0
        public async Task <ActionResult> GetStoredWebForm(string ObjectId, string ProcessId, string ProcessVersion, string ProcessBranch)
        {
            List <WebFormModel> webFormElements = new List <WebFormModel>();

            //Se o modelo de dados for nulo, logo estamos perante um caso de pedido inválido (Bad Request)
            if (string.IsNullOrEmpty(ProcessId))
            {
                return(BadRequest());
            }

            _Connection.DatabaseConnection();

            //Chamadas aos serviços - Ligação à base de dados
            _Metadata.SetDatabase(_Connection.GetDatabase());
            _Field.SetDatabase(_Connection.GetDatabase());
            _Properties.SetDatabase(_Connection.GetDatabase());
            _Data.SetDatabase(_Connection.GetDatabase());

            //Obter a lista de camposde um processo;
            List <string> processFields = _Metadata.GetProcessFieldsID(ProcessId);
            DataModel     dataModel     = _Data.GetDataModel(ObjectId, ProcessId, Convert.ToInt32(ProcessVersion), ProcessBranch);

            //Valores para preenchimento de campos hidden no formulário gerado automaticamente;
            ViewBag.ObjectId       = ObjectId;
            ViewBag.ProcessId      = ProcessId;
            ViewBag.ProcessVersion = ProcessVersion;
            ViewBag.ProcessBranch  = ProcessBranch;

            string ProcessFields = string.Empty;

            for (int j = 0; j < processFields.Count; j++)
            {
                FieldModel fieldModel = _Field.GetField(processFields.ElementAt(j));

                if (j == processFields.Count - 1)
                {
                    ProcessFields += fieldModel.Type;
                }
                else
                {
                    ProcessFields += fieldModel.Type + " ";
                }

                PropertiesModel propertiesModel = _Properties.GetProperties(fieldModel.Properties);

                WebFormModel webFormElement = new WebFormModel()
                {
                    Type      = fieldModel.Type,
                    Name      = fieldModel.Name,
                    Size      = propertiesModel.Size.ToString(),
                    Value     = dataModel.Data.ElementAt(j),
                    Maxlength = propertiesModel.Maxlength.ToString(),
                    Required  = propertiesModel.Required.ToString(),
                    Readonly  = false
                };

                ViewBag.Readonly = "false"; //Vraiavel para controlo da visibilidade do submit button;

                webFormElements.Add(webFormElement);
            }

            //Passar a lista de webform elements a uma classe que vai criar uma array com as linhas a serem renderizadas;
            WebFormTemplate webFormTemplate = new WebFormTemplate(webFormElements);
            List <string>   fragments       = webFormTemplate.Template();

            string template = string.Empty;

            for (int j = 0; j < fragments.Count; j++)
            {
                if (j == fragments.Count - 1)
                {
                    template += fragments[j];
                }
                else
                {
                    template += (fragments[j] + "|");
                }
            }

            ViewBag.Template = template;

            return(await Task.Run(() => View("WebFormGenerator")));
        }