예제 #1
0
        public static GC_Subjects SoftDelete(int id)
        {
            SinaicspDataModelContainer _context = new Sinaicsp_API.SinaicspDataModelContainer();
            GoalCatalog _item = _context.GoalCatalogs.FirstOrDefault(a => a.Id == id);

            _item.IsDeleted = true;
            _context.SaveChanges();
            return(_item.GC_Subjects);
        }
예제 #2
0
        public static bool Update(int id, string textGoal)
        {
            SinaicspDataModelContainer _context = new Sinaicsp_API.SinaicspDataModelContainer();
            GoalCatalog itemById = _context.GoalCatalogs.FirstOrDefault(a => a.Id == id);
            GoalCatalog _item    = itemById;

            _item.TextGoal = textGoal;
            _context.SaveChanges();
            return(true);
        }
예제 #3
0
        public static GC_Subjects MoveDown(int id)
        {
            SinaicspDataModelContainer _context = new Sinaicsp_API.SinaicspDataModelContainer();
            GoalCatalog _goalItem = _context.GoalCatalogs.Where(a => a.Id == id).FirstOrDefault();
            GC_Subjects _item     = _goalItem.GC_Subjects;

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

                int index = targetchildList.IndexOf(_goalItem);
                if (index > 0)
                {
                    GoalCatalog _goalAbove   = targetchildList[index - 1];
                    int         NeworderSwap = _goalAbove.SubTextOrder;
                    _goalAbove.SubTextOrder = _goalItem.SubTextOrder;
                    _goalItem.SubTextOrder  = NeworderSwap;
                }
            }
            _context.SaveChanges();
            return(_item);
        }