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); }
public void ReorderChildren() { var index = 0; var childMedias = ChildMedias.Where(i => i.MediaDetails.Any() && i.MediaDetails.ElementAt(0).MediaType.ShowInSiteTree).OrderBy(i => i.OrderIndex).ToList(); foreach (var mediaItem in childMedias) { var context = BaseMapper.GetObjectFromContext(mediaItem); if (context == null) { continue; } if (context.OrderIndex != index) { context.OrderIndex = index; MediasMapper.Update(context); } index++; } }