/// <summary> /// Deletes an <see cref="IMedia"/> object by moving it to the Recycle Bin /// </summary> /// <param name="media">The <see cref="IMedia"/> to delete</param> /// <param name="userId">Id of the User deleting the Media</param> public void MoveToRecycleBin(IMedia media, int userId = 0) { if (Trashing.IsRaisedEventCancelled(new MoveEventArgs <IMedia>(media, -21), this)) { return; } //Find Descendants, which will be moved to the recycle bin along with the parent/grandparent. var descendants = GetDescendants(media).OrderBy(x => x.Level).ToList(); var uow = _uowProvider.GetUnitOfWork(); using (var repository = _repositoryFactory.CreateMediaRepository(uow)) { media.ChangeTrashedState(true, -21); repository.AddOrUpdate(media); //Loop through descendants to update their trash state, but ensuring structure by keeping the ParentId foreach (var descendant in descendants) { descendant.ChangeTrashedState(true, descendant.ParentId); repository.AddOrUpdate(descendant); } uow.Commit(); } Trashed.RaiseEvent(new MoveEventArgs <IMedia>(media, false, -21), this); Audit.Add(AuditTypes.Move, "Move Media to Recycle Bin performed by user", userId, media.Id); }
/// <summary> /// Deletes an <see cref="IMedia"/> object by moving it to the Recycle Bin /// </summary> /// <param name="media">The <see cref="IMedia"/> to delete</param> /// <param name="userId">Id of the User deleting the Media</param> public void MoveToRecycleBin(IMedia media, int userId = 0) { if (Trashing.IsRaisedEventCancelled(new MoveEventArgs<IMedia>(media, -21), this)) return; //Find Descendants, which will be moved to the recycle bin along with the parent/grandparent. var descendants = GetDescendants(media).OrderBy(x => x.Level).ToList(); var uow = _uowProvider.GetUnitOfWork(); using (var repository = _repositoryFactory.CreateMediaRepository(uow)) { media.ChangeTrashedState(true, -21); repository.AddOrUpdate(media); //Loop through descendants to update their trash state, but ensuring structure by keeping the ParentId foreach (var descendant in descendants) { descendant.ChangeTrashedState(true, descendant.ParentId); repository.AddOrUpdate(descendant); } uow.Commit(); } Trashed.RaiseEvent(new MoveEventArgs<IMedia>(media, false, -21), this); Audit.Add(AuditTypes.Move, "Move Media to Recycle Bin performed by user", userId, media.Id); }