Esempio n. 1
0
        public async Task <CommandResult> Handle(RemoveTenantCommand request, CancellationToken cancellationToken)
        {
            Tenant entity = await _repo.FindByIdAsync(request.Id);

            if (entity == null)
            {
                return(new CommandResult(new InvalidOperationException($"Tenant not found (Id={request.Id})")));
            }

            entity.ConcurrencyToken = request.ConcurrencyToken;

            _repo.Delete(entity);

            await _repo.SaveChangesAsync();

            return(new CommandResult(true));
        }
Esempio n. 2
0
        public async Task <CommandResult <Tenant> > Handle(ModifyTenantCommand request, CancellationToken cancellationToken)
        {
            Tenant entity = await _repo.FindByIdAsync(request.Id);

            if (entity == null)
            {
                return(new CommandResult <Tenant>(new InvalidOperationException($"Tenant not found (Id={request.Id})")));
            }

            entity.Email            = request.Email;
            entity.Name             = request.Name;
            entity.ConcurrencyToken = request.ConcurrencyToken;

            _repo.Update(entity);

            await _repo.SaveChangesAsync();

            return(new CommandResult <Tenant>(entity));
        }