Ejemplo n.º 1
0
        private void CreateShortcut(SimpleTreeNode <Node> simpNode, Dictionary <string, List <ShortcutEntity> > shortcutDict)
        {
            var key = this.GetKey(simpNode.Data.Answer, simpNode.Data.ImageName);

            if (shortcutDict.ContainsKey(key))
            {
                var shortcuts = shortcutDict[key];
                var shortcut  = this.RemoveShortcut(shortcuts, simpNode.Data.Id);
                if (shortcuts.Count == 0)
                {
                    shortcutDict.Remove(key);
                }
                shortcut.Text      = simpNode.Data.Answer;
                shortcut.ImageName = simpNode.Data.ImageName;
                shortcut.Code      = simpNode.Data.Code;
                if (string.IsNullOrEmpty(shortcut.Title) && !string.IsNullOrEmpty(simpNode.Data.Question))
                {
                    shortcut.Title = simpNode.Data.Question;
                }
                simpNode.Tag = shortcut;
            }
            else
            {
                var shortcut = EntityHelper.Create <ShortcutEntity>(this._dbAccount);
                shortcut.Text      = simpNode.Data.Answer;
                shortcut.Code      = simpNode.Data.Code;
                shortcut.ImageName = simpNode.Data.ImageName;
                shortcut.Title     = simpNode.Data.Question;
                simpNode.Tag       = shortcut;
            }
        }
Ejemplo n.º 2
0
        public void CanCreateViaPermissionsAsGuest()
        {
            var settings = new Dictionary <string, object>();

            settings["Link"] = new Dictionary <string, object>();
            settings.GetSection("Link")["Create"] = "?";

            Auth.Init(new AuthWin("Admin", new UserPrincipal(1, "kishore", "normaluser", "custom", false)));

            var security = new EntitySettingsHelper(settings);
            var helper   = new EntityHelper <Link>(security);
            var link     = new Link()
            {
                Name = "helix cms", Url = "http://helixcms.com", Group = "sites", SortIndex = 2
            };
            var result = helper.Create(link);


            // This is a viewmodel
            Assert.AreEqual(result.Success, true);
            Assert.AreEqual(result.Message, string.Empty);
            Assert.IsNotNull(result.Item);
            Assert.AreNotEqual(result.ItemAs <Link>().Id, 0);
            Assert.IsNotNullOrEmpty(result.ItemAs <Link>().Name);
            Assert.IsTrue(result.IsAuthorized);
            Assert.IsTrue(result.IsAvailable);
        }
Ejemplo n.º 3
0
        private TreeNode CreateShortcutCatalog(ShortcutCatalogEntity fromCat, string dbAccount)
        {
            var shortcutCatalog = EntityHelper.Create <ShortcutCatalogEntity>(dbAccount);

            shortcutCatalog.Name = fromCat.Name;
            return(shortcutCatalog);
        }
Ejemplo n.º 4
0
        private void CreateNewShortcut(TreeNode tn, List <TreeNode> nds, SimpleTreeNode <Node> n)
        {
            ShortcutEntity shortcut;

            if (string.IsNullOrEmpty(n.Data.ImageName))
            {
                shortcut = (nds.FirstOrDefault(k => {
                    var sc = k as ShortcutEntity;
                    return(sc.Text == n.Data.Answer);
                }) as ShortcutEntity);
            }
            else
            {
                shortcut = (nds.FirstOrDefault(k =>
                {
                    var sc = k as ShortcutEntity;
                    return(sc.ImageName == n.Data.ImageName);
                }) as ShortcutEntity);
            }
            if (shortcut == null)
            {
                shortcut           = EntityHelper.Create <ShortcutEntity>(_dbAccount);
                shortcut.Text      = n.Data.Answer;
                shortcut.Code      = n.Data.Code;
                shortcut.ImageName = n.Data.ImageName;
                _dbAccessor.AddNodeToTargetNode(shortcut, tn.EntityId);
            }
            else if (shortcut.Code != n.Data.Code)
            {
                shortcut.Code = n.Data.Code;
                _dbAccessor.SaveNodeToDb(shortcut);
            }
        }
Ejemplo n.º 5
0
        public TreeCatalog CreateRootAndSaveToDb(string entityId)
        {
            TreeCatalog TreeCatalog = EntityHelper.Create(this._catalogType, this._dbAccount) as TreeCatalog;

            TreeCatalog.Name     = "Root!@#$Catalog$%&Header*&()";
            TreeCatalog.EntityId = entityId;
            this.SaveNodeToDb(TreeCatalog);
            return(TreeCatalog);
        }
Ejemplo n.º 6
0
        private TreeNode CreateShortcut(ShortcutEntity fromShortcut, string dbAccount)
        {
            var shortcut = EntityHelper.Create <ShortcutEntity>(dbAccount);

            shortcut.Text      = fromShortcut.Text;
            shortcut.ImageName = ShortcutImageHelper.AddNewImage(fromShortcut.ImageName);
            shortcut.Code      = fromShortcut.Code;
            return(shortcut);
        }
Ejemplo n.º 7
0
        public static BuyerNoteEntity Create(string buyerMain, string seller, string note)
        {
            string dbAccount = GetDbAccount(seller);
            var    et        = EntityHelper.Create <BuyerNoteEntity>(dbAccount);

            et.BuyerMainNick = buyerMain;
            et.Recorder      = seller;
            et.Note          = (note ?? "");
            et.RecordTime    = BatTime.Now;
            DbHelper.SaveToDb(et, true);
            return(et);
        }
        private void UpdateBuilders()
        {
            var entityHelper = EntityHelper.Create(Settings);
            var roots        = BuilderBase.GetRoots(Settings.Domain);
            var enums        = BuilderBase.GetEnums(Settings.Domain);

            Builders.Each(b =>
            {
                b.EntityHelper = entityHelper;
                b.Roots        = roots;
                b.Enums        = enums;
                b.Cancellation = CancellationTokenSource.Token;
            });
        }
Ejemplo n.º 9
0
        public static void CreateNew(string parentId, string dbAccount, string seller, Window ownnerWnd, Action <TreeNode> callback)
        {
            var wnd = new WndShortcutEditor(null, null, null);

            wnd.FirstShow(seller, ownnerWnd, () =>
            {
                if (wnd._isSubmit)
                {
                    var et       = EntityHelper.Create <ShortcutEntity>(dbAccount);
                    et.ParentId  = parentId;
                    et.Title     = wnd.tboxQuestion.Text.Trim();
                    et.Text      = wnd._data.Content;
                    et.Code      = wnd._data.Code;
                    et.ImageName = wnd.imgMain.Tag == null ? "" : wnd.imgMain.Tag.ToString();
                    callback(et);
                }
            }, false);
        }
Ejemplo n.º 10
0
        public static void Save <T>(string dbAccount, string key, T value)
        {
            var    et           = DbHelper.FirstOrDefault <HybridEntity>(dbAccount, k => k.Key == key);
            string wokeModeText = Util.SerializeWithTypeName(value);

            if (et == null)
            {
                et       = EntityHelper.Create <HybridEntity>(dbAccount);
                et.Key   = key;
                et.Value = wokeModeText;
                DbHelper.SaveToDb(et, true);
            }
            else if (et.Value != wokeModeText)
            {
                et.Value = wokeModeText;
                DbHelper.SaveToDb(et, true);
            }
        }
Ejemplo n.º 11
0
        public override void CreateCata(TreeNode p, Window wnd, Action <TreeNode> callback, object obj = null)
        {
            ShortcutCatalogEntity cata = null;

            this.ShowWndInput(p.EntityId, wnd, null, (text) => {
                if (text.xIsNullOrEmptyOrSpace())
                {
                    return;
                }
                cata          = EntityHelper.Create <ShortcutCatalogEntity>(this.DbAccount);
                cata.ParentId = p.EntityId;
                cata.Name     = text;
                if (callback != null)
                {
                    callback(cata);
                }
            });
        }
Ejemplo n.º 12
0
        public void CanCreate()
        {
            var helper = new EntityHelper <Link>();
            var link   = new Link()
            {
                Name = "helix cms", Url = "http://helixcms.com", Group = "sites", SortIndex = 2
            };
            var result = helper.Create(link);


            // This is a viewmodel
            Assert.AreEqual(result.Success, true);
            Assert.AreEqual(result.Message, string.Empty);
            Assert.IsNotNull(result.Item);
            Assert.AreNotEqual(result.ItemAs <Link>().Id, 0);
            Assert.IsNotNullOrEmpty(result.ItemAs <Link>().Name);
            Assert.IsTrue(result.IsAuthorized);
            Assert.IsTrue(result.IsAvailable);
        }
Ejemplo n.º 13
0
        private void CreateCata(SimpleTreeNode <Node> simpNode, Dictionary <string, List <ShortcutCatalogEntity> > shortcutCatalogDict, Dictionary <string, List <ShortcutEntity> > shortcutDict)
        {
            string answer = simpNode.Data.Answer;

            if (shortcutCatalogDict.ContainsKey(answer))
            {
                var catas = shortcutCatalogDict[answer];
                var tag   = this.RemoveCata(catas, simpNode.Data.Id);
                if (catas.Count == 0)
                {
                    shortcutCatalogDict.Remove(answer);
                }
                simpNode.Tag = tag;
            }
            else
            {
                var cata = EntityHelper.Create <ShortcutCatalogEntity>(this._dbAccount);
                cata.Name    = answer;
                simpNode.Tag = cata;
            }
            this.CreateNodeTree(simpNode, shortcutCatalogDict, shortcutDict);
        }
Ejemplo n.º 14
0
        private void TraverseCreateNewNode(TreeNode tn, SimpleTreeNode <Node> n)
        {
            var cata = EntityHelper.Create <ShortcutCatalogEntity>(_dbAccount);

            cata.Name = n.Data.Answer;
            _dbAccessor.AddNodeToTargetNode(cata, tn.EntityId);
            foreach (var simpNode in n.Children)
            {
                if (simpNode.Data.IsCatalog)
                {
                    TraverseCreateNewNode(cata, simpNode);
                }
                else
                {
                    var shortcut = EntityHelper.Create <ShortcutEntity>(_dbAccount);
                    shortcut.Text      = simpNode.Data.Answer;
                    shortcut.Code      = simpNode.Data.Code;
                    shortcut.ImageName = simpNode.Data.ImageName;
                    _dbAccessor.AddNodeToTargetNode(shortcut, cata.EntityId);
                }
            }
        }
Ejemplo n.º 15
0
 private void BtnOk_Click(object sender, RoutedEventArgs e)
 {
     if (_data.Submitable())
     {
         if (this.xIsModal())
         {
             base.DialogResult = new bool?(true);
         }
         if (_pre == null)
         {
             _result         = EntityHelper.Create <FavoriteNoteEntity>(_sellerMain);
             _result.Creator = _sellerMain;
             _result.Note    = _data.Text;
         }
         else
         {
             _result         = _pre;
             _result.Creator = _sellerMain;
             _result.Note    = _data.Text;
         }
         DbHelper.SaveToDb(_result, true);
         Close();
     }
 }