/// <summary>
        /// 根据对象ID删除对象
        /// </summary>
        /// <param name="id"></param>
        /// <returns>删除成功与否</returns>
        public bool Remove(TId id)
        {
            var old = DataList.FirstOrDefault(d => d.Id.Equals(id));

            if (old != null && Provider.Delete(old) > 0)
            {
                var r = DataList.Remove(old);
                AfterSaved?.Invoke(old);
                return(r);
            }
            return(false);
        }
        /// <summary>
        /// 新增对象
        /// </summary>
        /// <param name="t"></param>
        public void Add(T t)
        {
            if (!CheckValidName(t))
            {
                throw new JException(t.Name + "的名称重复。");
            }

            BeforeSave?.Invoke(t);
            if (Provider.Add(t) > 0)
            {
                DataList.Add(t);
                AfterSaved?.Invoke(t);
            }
            if (t.Id == null)
            {
                throw new JException("ID is empty");
                //t.Id = CreateId();
            }
        }
        /// <summary>
        /// 修改对象
        /// </summary>
        /// <param name="t"></param>
        /// <returns>修改成功与否</returns>
        public bool Change(T t)
        {
            var old = DataList.FirstOrDefault(d => d.Id.Equals(t.Id));

            if (old == null)
            {
                throw new JException(t.Name + "Not found。");
            }
            old.Name = t.Name;
            if (!CheckValidName(old))
            {
                throw new JException(t.Name + " duplicated。");
            }

            BeforeSave?.Invoke(t);
            if (Provider.Change(t) > 0)
            {
                DataList[DataList.IndexOf(old)] = t;
                AfterSaved?.Invoke(t);
                return(true);
            }
            return(false);
        }
Beispiel #4
0
        public int OnAfterSave(uint docCookie)
        {
            AfterSaved?.Invoke(this, docCookie);

            return(VSConstants.S_OK);
        }