示例#1
0
        public IHttpActionResult Move(MoveBinding model)
        {

            _PageService.Move(model, User.Identity.GetUserId());
            return Ok();
        }
示例#2
0
        public void Move(MoveBinding Model, string UserID)
        {
            using (var _c = db)
            {
                var _P = _c.Pages.Where(m => m.PageID == Model.PageID).SingleOrDefault();
                Can(_P.SiteID, UserID, _c);
                var _Item = (from p in _c.Pages
                             where p.PageID == Model.PageID
                             select p).SingleOrDefault();
                if (Model.PageParentID == _Item.PageParentID)
                {
                    _c.Database.ExecuteSqlCommand(@"UPDATE Pages SET Priority=Priority+1 
WHERE SiteID={0} AND PageParentID={1} AND Priority>={2} AND Priority < {3} AND  PageID<>{4}", _Item.SiteID, Model.PageParentID, Model.Index, _Item.Priority, Model.PageID);

                    _c.Database.ExecuteSqlCommand(@"UPDATE Pages SET Priority=Priority-1 
WHERE SiteID={0} AND PageParentID={1} AND Priority<= {2} AND Priority >{3} AND PageID<>{4}", _Item.SiteID, _Item.PageParentID, Model.Index, _Item.Priority, Model.PageID);
                }
                else
                {
                    //SUBSTRACT OLD PARENT ID
                    _c.Database.ExecuteSqlCommand(@"UPDATE Pages SET Priority=Priority-1 
WHERE SiteID={0} AND PageParentID={1} AND Priority>= {2}  AND PageID<>{3}", _Item.SiteID, _Item.PageParentID, _Item.Priority, Model.PageID);
                    //SUM NEW PARENT ID
                    _c.Database.ExecuteSqlCommand(@"UPDATE Pages SET Priority=Priority+1 
WHERE SiteID={0} AND PageParentID={1} AND Priority>={2} AND PageID<>{3}", _Item.SiteID, Model.PageParentID, Model.Index, Model.PageID);

                }

                _Item.PageParentID = Model.PageParentID;
                _Item.Priority = Model.Index;
                _c.SaveChanges();

            }
        }