Пример #1
0
        public async Task <Unit> Handle(AddBookCommand request, CancellationToken cancellationToken)
        {
            var book = new Book {
                Name = request.Name
            };
            await _context.Books.AddAsync(book, cancellationToken);

            await _context.SaveChangesAsync();

            return(Unit.Value);
        }
Пример #2
0
 public async Task Handle(ICommand <T> command)
 {
     if (command is AddCommand <T> )
     {
         _context.Set <T>().Add(command.Value);
     }
     if (command is EditCommand <T> )
     {
         _context.Set <T>().Update(command.Value);
     }
     if (command is DeleteCommand <T> )
     {
         _context.Set <T>().Remove(command.Value);
     }
     await _context.SaveChangesAsync();
 }