public async Task <IActionResult> GetExistingTenantByTenantDetails([FromBody] TenantForCheckDto tenant) { try { Tenant tenantExists = await _repositoryWrapper.Tenant.GetTenantByTenantDetails(tenant); ApplicationUser applicationUser = await _identityService.GetApplicationUserTenantByEmail(tenant.Email); /* verify if tenant exist, and is tenant as AppUser */ if (tenantExists == null || applicationUser == null) { _logger.LogError($"Landlord tried to check if tenant exist, but tenant, or application user does not exist: tenant email: {tenant.Email}"); return(BadRequest($"No such user or provided user details incorrect.")); } /* application user constrainted with tenant */ if (tenantExists.AspNetUsersId != applicationUser.Id) { _logger.LogError($"Landlord tried to check if tenant exist, but provided application user id: {applicationUser.Id} mismatch provided tenant id: {tenantExists.AspNetUsersId}"); return(BadRequest("Tenant and application user mismatch")); } _logger.LogInfo($"Tenant in applicationUser: {applicationUser.Tenant} landlord: {applicationUser.Landlord}"); return(Ok(tenantExists)); } catch (Exception e) { _logger.LogError($"Something went wrong inside GetTenantByTenantDetails(TenantForCheckDto) action: {e.ToString()}"); return(StatusCode(500, e.Message)); } }
public async Task <Tenant> GetTenantByTenantDetails(TenantForCheckDto tenant) { return(await FindByCondition(t => t.PhoneNumber.Equals(tenant.PhoneNumber)) .Where(t => (t.NIP.Equals(tenant.NIP)) || (t.PESEL.Equals(tenant.PESEL))) .FirstOrDefaultAsync()); }