public async Task AssignAdviseGroup(DiscModel disc, AdviseGroupModel adviseGroup, CancellationToken cancellationToken) { var hasAdviseGroup = disc.AdviseGroup != null; disc.AdviseGroup = adviseGroup; await discsRepository.UpdateDisc(disc, cancellationToken); if (hasAdviseGroup) { await DeleteOrphanAdviseGroups(cancellationToken); } }
public async Task UpdateDisc(DiscModel disc, Action <DiscModel> updateAction, CancellationToken cancellationToken) { var currentDisc = disc.CloneShallow(); updateAction(disc); if (!disc.IsDeleted && disc.TreeTitle != currentDisc.TreeTitle) { await storageRepository.UpdateDiscTreeTitle(currentDisc, disc, cancellationToken); } if (disc.AlbumTitle != currentDisc.AlbumTitle || disc.Year != currentDisc.Year) { foreach (var song in disc.ActiveSongs) { await storageRepository.UpdateSong(song, cancellationToken); // Update in repository should be performed after update in the storage, because later updates song checksum. await songsRepository.UpdateSong(song, cancellationToken); } } await discsRepository.UpdateDisc(disc, cancellationToken); }
public async Task AddDiscs(AdviseSetModel adviseSet, IEnumerable <DiscModel> addedDiscs, CancellationToken cancellationToken) { var lastAdviseSetInfo = GetAdviseSetDiscs(adviseSet).LastOrDefault()?.AdviseSetInfo; var nextOrder = (lastAdviseSetInfo?.Order ?? 0) + 1; foreach (var addedDisc in addedDiscs) { addedDisc.AdviseSetInfo = new AdviseSetInfo(adviseSet, nextOrder++); await discsRepository.UpdateDisc(addedDisc, cancellationToken); } }