public ActionResult RuleOrder(policyData vData, int id, int linkId, FormCollection collection) { RuleEntity rule = new RuleEntity(id); RuleCollection coll = new RuleCollection(); PredicateExpression pe = new PredicateExpression(RuleFields.Id != rule.Id); pe.Add(RuleFields.PolicyId == rule.PolicyId); SortExpression se = null; if (collection["up"] != null) { // Find all categories with display index less than ours. pe.Add(RuleFields.Order <= rule.Order); // Order by display index, highest first. se = new SortExpression(RuleFields.Order | SortOperator.Descending); } else { // Find all categories with display index greater than ours. pe.Add(RuleFields.Order >= rule.Order); // Order by display index, lowest first. se = new SortExpression(RuleFields.Order | SortOperator.Ascending); } // Swap with closest one. if (coll.GetMulti(pe, 1, se) && coll.Count > 0) { int temp = coll[0].Order; coll[0].Order = rule.Order; rule.Order = temp; rule.Save(); coll.SaveMulti(); } return(RedirectToAction("EditPolicy", new { id = linkId })); }
public ActionResult RuleOrder(policyData vData, int id, int linkId, FormCollection collection) { RuleEntity rule = new RuleEntity(id); RuleCollection coll = new RuleCollection(); PredicateExpression pe = new PredicateExpression(RuleFields.Id != rule.Id); pe.Add(RuleFields.PolicyId == rule.PolicyId); SortExpression se = null; if (collection["up"] != null) { // Find all categories with display index less than ours. pe.Add(RuleFields.Order <= rule.Order); // Order by display index, highest first. se = new SortExpression(RuleFields.Order | SortOperator.Descending); } else { // Find all categories with display index greater than ours. pe.Add(RuleFields.Order >= rule.Order); // Order by display index, lowest first. se = new SortExpression(RuleFields.Order | SortOperator.Ascending); } // Swap with closest one. if (coll.GetMulti(pe, 1, se) && coll.Count > 0) { int temp = coll[0].Order; coll[0].Order = rule.Order; rule.Order = temp; rule.Save(); coll.SaveMulti(); } return RedirectToAction("EditPolicy", new { id = linkId }); }