Example #1
0
        public async Task <Result <Guid> > Handle(TenantCreateCommand request, CancellationToken cancellationToken)
        {
            var isTenantDuplicating = await _repository.AnyAsync(x => x.Logon.Equals(request.Logon), cancellationToken);

            if (isTenantDuplicating)
            {
                return(Result.Failure <Guid>(ErrorType.Duplicating.ToString()));
            }

            var tenant = _mapper.Map <Tenant>(request);

            tenant.Salt     = _hashing.GenerateSalt();
            tenant.Password = _hashing.GenerateHash(request.Password, tenant.Salt);

            var createdTenant = await _repository.CreateAsync(tenant, cancellationToken);

            return(await CommitAsync() > 0
                ? createdTenant.ID
                : Result.Failure <Guid>(ErrorType.SaveChangesFailure.ToString()));
        }