public async Task <bool> Handle(DeleteStudentCommand request, CancellationToken cancellationToken) { Student entity; entity = await _context.Students.FindAsync(request.Id.Value); entity.IsDeleted = 1; await _context.SaveChangesAsync(cancellationToken); return(true); }
public async Task <Guid> Handle(UpsertStudentCommand request, CancellationToken cancellationToken) { Student entity; if (request.Id.HasValue) { // Update command. entity = await _context.Students.FindAsync(request.Id.Value); } else { entity = new Student(); _context.Students.Add(entity); entity.IsDeleted = 0; } entity.Name = request.Name; entity.Email = request.Email; await _context.SaveChangesAsync(cancellationToken); return(entity.Id); }