public ActionResult SubmitBusinessObject(int id)
        {
            var schemastring = _BOdb.BusinessObjects.Find(id).JsonSchema;


            // string flat = Request.Form.ToString().Replace("%5b", "[").Replace("%5d", "]");
            // string jsonstring = FlatJson.FlatJsonToJsonTree(flat, schemastring);

            string jsonstring = FlatJson.RequestFormToJsonTree(Request.Form, schemastring);

            JObject data = JObject.Parse(jsonstring);



            JsonSchema schema = JsonSchema.Parse(schemastring);

            IList <string> messages;
            bool           valid = data.IsValid(schema, out messages);


            if (valid)
            {
                ViewBag.BObjectIdentifier = id;
                ViewBag.Json = jsonstring;

                Dictionary <string, string> model = new Dictionary <string, string>();
                model.Add("json", jsonstring);

                return(PartialView(model));
            }
            else
            {
                BORender    bor    = new BORender();
                string      boview = _BOdb.BusinessObjects.Find(id).ViewData;
                ViewBOModel model  = new ViewBOModel();
                //dynamic model = Newtonsoft.Json.JsonConvert.DeserializeObject<dynamic>(jsonstring);
                model.BObjectIdentifier = id;
                // model.BObjectSchema = JObject.Parse(schemastring);
                model.BObjectErrors = new List <string>(messages);
                model.ViewData      = bor.createHTML(jsonstring, schemastring, boview);


                return(PartialView("PreviewBO", model));
            }
        }
Example #2
0
        public ActionResult SubmitBusinessObject(int id, int taskId)
        {
            bool userhaseditrights = false;

            JobsHelper jhelper = new JobsHelper();

            var task = _inFlowDb.T_Tasks.Find(taskId);
            var boi  = _db.BusinessObjectInstances.Find(id);

            if (!task.Done)
            {
                bool usercanaccessTask = jhelper.CanUserAccessTask(taskId, User.Identity.Name);

                if (usercanaccessTask)
                {
                    if (task.EditableParameters.Contains("{\"Type\":\"bobasic\",\"Value\":{\"bo\":"
                                                         + boi.BusinessObjectId + ",\"boi\":"
                                                         + boi.Id + "}}"))
                    {
                        userhaseditrights = true;
                    }
                }
            }

            if (userhaseditrights)
            {
                var schemastring = _db.BusinessObjectInstances.Find(id).BusinessObject.JsonSchema;



                string jsonstring = FlatJson.RequestFormToJsonTree(Request.Form, schemastring);

                JObject data = JObject.Parse(jsonstring);



                JsonSchema schema = JsonSchema.Parse(schemastring);

                IList <string> messages;
                bool           valid = data.IsValid(schema, out messages);

                if (valid)
                {
                    ViewBag.BObjectIdentifier = id;
                    ViewBag.Json = jsonstring;

                    boi      = _db.BusinessObjectInstances.Find(id);
                    boi.Data = jsonstring;
                    _db.SaveChanges();

                    Dictionary <string, string> model = new Dictionary <string, string>();
                    model.Add("json", jsonstring);

                    return(PartialView(model));
                }
                else
                {
                    boi = _db.BusinessObjectInstances.Find(id);
                    BORender bor = new BORender();

                    ViewBOModel model = new ViewBOModel();
                    //dynamic model = Newtonsoft.Json.JsonConvert.DeserializeObject<dynamic>(jsonstring);
                    model.BObjectIdentifier = id;
                    // model.BObjectSchema = JObject.Parse(schemastring);
                    model.BObjectErrors = new List <string>(messages);
                    model.ViewData      = bor.createHTML(jsonstring, boi.BusinessObject.JsonSchema, boi.BusinessObject.ViewData);
                    ViewBag.TaskId      = taskId;

                    return(PartialView("BusinessObject", model));
                }
            }
            else
            {
                return(PartialView("Accessdenied"));
            }
        }