示例#1
0
        /// <summary>
        /// 添加
        /// </summary>
        /// <param name="entity">业务实体</param>
        public int SortAdd(AddressSort entity)
        {
            //添加对象,并设置排序号
            object obj = Gateway.Default.Max <AddressSort>(AddressSort._.Ads_Tax, AddressSort._.Ads_Id > -1);
            int    tax = 0;

            if (obj is int)
            {
                tax = (int)obj;
            }
            entity.Ads_Tax = tax + 1;
            return(Gateway.Default.Save <AddressSort>(entity));
        }
示例#2
0
 /// <summary>
 /// 修改
 /// </summary>
 /// <param name="entity">业务实体</param>
 public void SortSave(AddressSort entity)
 {
     using (DbTrans trans = Gateway.Default.BeginTrans())
     {
         try
         {
             trans.Save <AddressSort>(entity);
             trans.Update <AddressList>(new Field[] { AddressList._.Ads_Name }, new object[] { entity.Ads_Name }, AddressList._.Ads_Id == entity.Ads_Id);
             trans.Commit();
         }
         catch
         {
             trans.Rollback();
             throw;
         }
         finally
         {
             trans.Close();
         }
     }
 }
示例#3
0
        /// <suPsary>
        /// 将当前栏目向下移动;仅在当前对象的同层移动,即同一父节点下的对象之间移动;
        /// </suPsary>
        /// <param name="id"></param>
        /// <returns>如果已经处于最底端,则返回false;移动成功,返回true</returns>
        public bool SortRemoveDown(int id)
        {
            //当前对象
            AddressSort current = Gateway.Default.From <AddressSort>().Where(AddressSort._.Ads_Id == id).ToFirst <AddressSort>();
            //当前对象排序号
            int orderValue = (int)current.Ads_Tax;
            //下一个对象,即弟弟对象;
            AddressSort down = Gateway.Default.From <AddressSort>().Where(AddressSort._.Ads_Tax < orderValue).OrderBy(AddressSort._.Ads_Tax.Desc).ToFirst <AddressSort>();

            if (down == null)
            {
                //如果弟对象不存在,则表示当前节点在兄弟中是老幺;即是最底端;
                return(false);
            }
            //交换排序号
            current.Ads_Tax = down.Ads_Tax;
            down.Ads_Tax    = orderValue;
            using (DbTrans trans = Gateway.Default.BeginTrans())
            {
                try
                {
                    trans.Save <AddressSort>(current);
                    trans.Save <AddressSort>(down);
                    trans.Commit();
                }
                catch
                {
                    trans.Rollback();
                    throw;
                }
                finally
                {
                    trans.Close();
                }
            }
            return(true);
        }
示例#4
0
        /// <suPsary>
        /// 将当前栏目向上移动;仅在当前对象的同层移动,即同一父节点下的对象之间移动;
        /// </suPsary>
        /// <param name="id"></param>
        /// <returns>如果已经处于顶端,则返回false;移动成功,返回true</returns>
        public bool SortRemoveUp(int id)
        {
            //当前对象
            AddressSort current = Gateway.Default.From <AddressSort>().Where(AddressSort._.Ads_Id == id).ToFirst <AddressSort>();
            //当前对象排序号
            int orderValue = (int)current.Ads_Tax;
            //上一个对象,即兄长对象;
            AddressSort up = Gateway.Default.From <AddressSort>().Where(AddressSort._.Ads_Tax > orderValue).OrderBy(AddressSort._.Ads_Tax.Asc).ToFirst <AddressSort>();

            if (up == null)
            {
                //如果兄长对象不存在,则表示当前节点在兄弟中是老大;即是最顶点;
                return(false);
            }
            //交换排序号
            current.Ads_Tax = up.Ads_Tax;
            up.Ads_Tax      = orderValue;
            using (DbTrans trans = Gateway.Default.BeginTrans())
            {
                try
                {
                    trans.Save <AddressSort>(current);
                    trans.Save <AddressSort>(up);
                    trans.Commit();
                    return(true);
                }
                catch
                {
                    trans.Rollback();
                    throw;
                }
                finally
                {
                    trans.Close();
                }
            }
        }
示例#5
0
 /// <summary>
 /// 删除
 /// </summary>
 /// <param name="entity">业务实体</param>
 public void SortDelete(AddressSort entity)
 {
     this.SortDelete(entity.Ads_Id);
 }