Пример #1
0
            public async Task <Guid> Handle(CreateAssignmentCommand request, CancellationToken cancellationToken)
            {
                var entity = new Assignment
                {
                    Title = request.Title,
                    Body  = request.Body
                };

                _context.Assignments.Add(entity);

                await _context.SaveChangesAsync(cancellationToken);

                return(entity.Id);
            }
Пример #2
0
            public async Task <Unit> Handle(DeleteAssignmentCommand request, CancellationToken cancellationToken)
            {
                var entity = await _context.Assignments.FindAsync(request.Id);

                if (entity == null)
                {
                    throw new EntityNotFoundException(nameof(Assignment), request.Id);
                }

                _context.Assignments.Remove(entity);

                await _context.SaveChangesAsync(cancellationToken);

                return(Unit.Value);
            }