Example #1
0
        public Task <Unit> Handle(DeleteCopy request, CancellationToken cancellationToken)
        {
            var copy = _context.Copies.Single(c => c.Id == request.CopyId);

            _context.Remove(copy);

            _context.SaveChanges();

            return(Unit.Task);
        }
        private async Task RemoveUnusedAssociations(CancellationToken cancellationToken,
                                                    List <TitleGenre> existingAssociations,
                                                    List <Guid> associated)
        {
            var difference = existingAssociations.Where(ea => associated.All(a => ea.GenreId != a));

            foreach (var toRemove in difference)
            {
                _context.Remove(toRemove);

                await _context.SaveChangesAsync(cancellationToken);
            }
        }