示例#1
0
 public void UpOrDown(UpOrDown Model, string UserID)
 {
     using (var _c = db)
     {
         var _Category = GetByID(Model.CategoryID, _c);
         Can(_Category.SiteID, UserID, _c);
         var _P = _c.Categories.Where(m => m.CategoryParentID == _Category.CategoryParentID && m.SiteID == _Category.SiteID);
         if (Model.Up)
         {
             if (_P.Select(m => m.Priority).Min() < _Category.Priority)
             {
                 var _Next = _P.Where(m => m.Priority < _Category.Priority).OrderBy(m => m.Priority).ToList().Last();
                 _Next.Priority++;
                 _Category.Priority--;
             }
         }
         else
         {
             if (_P.Select(m => m.Priority).Max() > _Category.Priority)
             {
                 var _Next = _P.Where(m => m.Priority > _Category.Priority).OrderBy(m => m.Priority).ToList().First();
                 _Next.Priority--;
                 _Category.Priority++;
             }
         }
         _c.SaveChanges();
     }
 }
 public IHttpActionResult PostUpOrDown(UpOrDown Model)
 {
     _CategoryService.UpOrDown(Model, User.Identity.GetUserId());
     return Ok();
 }