Ejemplo n.º 1
0
    public void DeleteKeyword(Keyword keyword) {
      //TODO: SubmitChanges can submit other not commited changes as well!!
      foreach (var mik in ACore.Db.MediaItemKeywords.Where(x => x.KeywordId == keyword.Id)) {
        ACore.Db.DeleteOnSubmit(mik);
      }

      ACore.Db.DeleteOnSubmit(keyword.Data);
      ACore.Db.SubmitChanges();
      AllKeywords.Remove(keyword);

      var items = keyword.Parent == null ? Items : keyword.Parent.Items;
      items.Remove(keyword);
    }
Ejemplo n.º 2
0
    public Keyword CreateKeyword(BaseTreeViewItem root, string name) {
      if (root == null) return null;

      var parent = root as Keyword;
      var dmKeyword = new DataModel.Keyword {
        Id = ACore.Db.GetNextIdFor<DataModel.Keyword>(),
        Name = parent == null ? name : $"{parent.FullPath}/{name}"
      };
      ACore.Db.Insert(dmKeyword);

      var vmKeyword = new Keyword(dmKeyword) {Parent = root};
      AllKeywords.Add(vmKeyword);

      try {
        Keyword keyword = root.Items.Cast<Keyword>().FirstOrDefault(k => k.Index == 0 && string.Compare(k.Title, name, StringComparison.OrdinalIgnoreCase) >= 0);
        root.Items.Insert(keyword == null ? 0 : root.Items.IndexOf(keyword), vmKeyword);
      }
      catch (Exception ex) {
        //BUG This type of CollectionView does not support changes to its SourceCollection from a thread different from the Dispatcher thread.
      }

      return vmKeyword;
    }