Ejemplo n.º 1
0
        public static CSP MoveDown(int id)
        {
            SinaicspDataModelContainer _context  = new Sinaicsp_API.SinaicspDataModelContainer();
            CSPGoalCatalog             _goalItem = _context.CSPGoalCatalogs.Where(a => a.Id == id).FirstOrDefault();
            CSP _item = _goalItem.CSP;

            if (_goalItem.ParentCSPGoalCatalogId == null)
            {
                List <CSPGoalCatalog> targetParentList = _item.CSPGoalCatalogs.Where(a => a.ParentCSPGoalCatalogId == null).OrderByDescending(a => a.TextOrder).ToList();
                int index = targetParentList.IndexOf(_goalItem);
                if (index > 0)
                {
                    CSPGoalCatalog _goalAbove   = targetParentList[index - 1];
                    int            NeworderSwap = _goalAbove.TextOrder;
                    _goalAbove.TextOrder = _goalItem.TextOrder;
                    _goalItem.TextOrder  = NeworderSwap;
                    foreach (CSPGoalCatalog item in _goalItem.CSPGoalCatalogs)
                    {
                        item.TextOrder = _goalItem.TextOrder;
                    }
                    foreach (CSPGoalCatalog item in _goalAbove.CSPGoalCatalogs)
                    {
                        item.TextOrder = _goalAbove.TextOrder;
                    }
                }
            }
            else
            {
                CSPGoalCatalog        _parent         = _goalItem.ParentCSPGoalCatalog;
                List <CSPGoalCatalog> targetchildList = _parent.CSPGoalCatalogs.OrderByDescending(a => a.SubTextOrder).ToList();

                int index = targetchildList.IndexOf(_goalItem);
                if (index > 0)
                {
                    CSPGoalCatalog _goalAbove   = targetchildList[index - 1];
                    int            NeworderSwap = _goalAbove.SubTextOrder;
                    _goalAbove.SubTextOrder = _goalItem.SubTextOrder;
                    _goalItem.SubTextOrder  = NeworderSwap;
                }
            }
            _context.SaveChanges();
            return(_item);
        }
Ejemplo n.º 2
0
        public static void AdjustOrder(int id)
        {
            SinaicspDataModelContainer _context = new Sinaicsp_API.SinaicspDataModelContainer();
            CSP _item = _context.CSPs.Where(a => a.Id == id).FirstOrDefault();

            if (_item.CSPGoalCatalogs.Count() > 0 && _item.CSPGoalCatalogs.Select(a => a.TextOrder).Max() == 0)
            {
                List <CSPGoalCatalog> parentGoals = _item.CSPGoalCatalogs.Where(a => a.ParentCSPGoalCatalogId == null).ToList();
                for (int i = 0; i < parentGoals.Count; i++)
                {
                    parentGoals.ElementAt(i).TextOrder = i;
                    if (parentGoals.ElementAt(i).CSPGoalCatalogs.Count() > 0)
                    {
                        for (int x = 0; x < _item.CSPGoalCatalogs.ElementAt(i).CSPGoalCatalogs.Count(); x++)
                        {
                            _item.CSPGoalCatalogs.ElementAt(i).CSPGoalCatalogs.ElementAt(x).TextOrder    = i;
                            _item.CSPGoalCatalogs.ElementAt(i).CSPGoalCatalogs.ElementAt(x).SubTextOrder = x;
                        }
                    }
                }
                _context.SaveChanges();
            }
        }