Example #1
0
        public Return MoveToIndex(int insertAtIndex)
        {
            var returnObj = BaseMapper.GenerateReturn();

            if (insertAtIndex < 0)
            {
                var ex = new System.Exception("Cant move to index: " + insertAtIndex);
                returnObj.Error = ErrorHelper.CreateError(ex);

                return(returnObj);
            }

            var siblings     = GetSiblings();
            var currentIndex = GetIndex(siblings);

            if (currentIndex >= 0 && currentIndex <= siblings.Count)
            {
                siblings.RemoveAt(currentIndex);
            }

            if (siblings.Count < insertAtIndex)
            {
                var ex = new System.Exception("Cant move to index: " + insertAtIndex);
                returnObj.Error = ErrorHelper.CreateError(ex);

                return(returnObj);
            }

            siblings.Insert(insertAtIndex, this);

            var index = 0;

            foreach (var media in siblings)
            {
                if (media.OrderIndex == index)
                {
                    index++;
                    continue;
                }

                var inContext = BaseMapper.GetObjectFromContext(media);
                media.OrderIndex = index;
                returnObj        = MediasMapper.Update(media);

                index++;
            }

            MediasMapper.ClearCache();
            MediaDetailsMapper.ClearCache();

            return(returnObj);
        }