Esempio n. 1
0
 public IHttpActionResult PostMove(ProductUpdatePriorities Model)
 {
     return Ok(_ProductService.UpdatePriorities(Model, User.Identity.GetUserId()));
 }
Esempio n. 2
0
 public int UpdatePriorities(ProductUpdatePriorities Model, string UserID)
 {
     using (var _c = db)
     {
         if (Model.CategoryID > 0)
         {
             var _P = GetProductCategory(Model.ProductID, Model.CategoryID, _c);
             Can(_P.Product.SiteID, UserID, _c);
             if (Model.Index > _P.Priority)
             {
                 var _OP = _c.ProductCategories.Where(m => m.CategoryID == Model.CategoryID && m.Priority > _P.Priority && m.Priority <= Model.Index).ToList();
                 foreach (var item in _OP)
                 {
                     item.Priority--;
                 }
             }
             else if (Model.Index < _P.Priority)
             {
                 var _OP = _c.ProductCategories.Where(m => m.CategoryID == Model.CategoryID && m.Priority < _P.Priority && m.Priority >= Model.Index).ToList();
                 foreach (var item in _OP)
                 {
                     item.Priority++;
                 }
             }
             _P.Priority = Model.Index;
             _c.SaveChanges();
             return _P.Priority;
         }
         return 0;
     }
 }