public JsonpResult ChangeRelation(string clientid,
                                          string modalid,
                                          string modalitemid,
                                          string relation)
        {
            Tz.Core.ComponentModal cm = new Core.ComponentModal(clientid, modalid);
            var rs = Newtonsoft.Json.JsonConvert.DeserializeObject <List <Models.LinkComponentField> >(relation);
            var ls = new List <Tz.Core.LinkComponentField>();

            foreach (Models.LinkComponentField lf in rs)
            {
                if (lf.ModalItemRelationID == null)
                {
                    lf.ModalItemRelationID = "";
                }
                ls.Add(new Core.LinkComponentField()
                {
                    ModalItemRelationID = lf.ModalItemRelationID,
                    Child            = lf.Child,
                    Parent           = lf.Parent,
                    ParentField      = lf.ParentField,
                    ParentFieldName  = "",
                    RelatedField     = lf.RelatedField,
                    RelatedFieldName = ""
                });
            }
            return(new JsonpResult(cm.AddRelation(modalitemid, ls)));
        }
        public JsonpResult UpdateModal(string clientid,
                                       string modalid,
                                       string name,
                                       string category,
                                       string nodes)
        {
            Tz.Core.ComponentModal cm = new Core.ComponentModal(clientid, modalid);
            cm.ModalName = name;
            cm.Category  = category;
            cm.Update();
            var att = Newtonsoft.Json.JsonConvert.DeserializeObject <List <Models.ComponentModalNode> >(nodes);

            foreach (Models.ComponentModalNode n in att)
            {
                var list = new List <Tz.Core.LinkComponentField>();
                foreach (Models.LinkComponentField lf in n.Relations)
                {
                    if (lf.IsRemoved == true)
                    {
                        cm.RemoveItemRelationship(n.ComponentModalItemID, lf.ModalItemRelationID);
                    }
                    if (lf.ModalItemRelationID == null)
                    {
                        lf.ModalItemRelationID = "";
                    }
                    list.Add(new Core.LinkComponentField()
                    {
                        ModalItemRelationID = lf.ModalItemRelationID,
                        Child            = lf.Child,
                        Parent           = lf.Parent,
                        ParentField      = lf.ParentField,
                        ParentFieldName  = "",
                        RelatedField     = lf.RelatedField,
                        RelatedFieldName = ""
                    });
                }
                if (n.ComponentModalItemID != "")
                {
                    cm.AddRelation(n.ComponentModalItemID, list);
                }
                else
                {
                    cm.AddNode(n.ComponentID, n.ChildComponentID, list);
                }
            }
            return(new JsonpResult(true));
        }