/// <summary> /// Moves an <see cref="IMedia"/> object to a new location /// </summary> /// <param name="media">The <see cref="IMedia"/> to move</param> /// <param name="parentId">Id of the Media's new Parent</param> /// <param name="userId">Id of the User moving the Media</param> public void Move(IMedia media, int parentId, int userId = 0) { using (new WriteLock(Locker)) { //This ensures that the correct method is called if this method is used to Move to recycle bin. if (parentId == -21) { MoveToRecycleBin(media, userId); return; } if (Moving.IsRaisedEventCancelled(new MoveEventArgs <IMedia>(media, parentId), this)) { return; } media.ParentId = parentId; Save(media, userId); //Ensure that Path and Level is updated on children var children = GetChildren(media.Id); if (children.Any()) { var parentPath = media.Path; var parentLevel = media.Level; var updatedDescendents = UpdatePathAndLevelOnChildren(children, parentPath, parentLevel); Save(updatedDescendents, userId); } Moved.RaiseEvent(new MoveEventArgs <IMedia>(media, false, parentId), this); Audit.Add(AuditTypes.Move, "Move Media performed by user", userId, media.Id); } }