public async Task <AuthenticateResponseDto> AuthenticateAsync(AuthenticateRequestDto request, string ipv4Address, string ipv6Address) { await _authenticateRequestValidator.ValidateAndThrowAsync(request); var account = _dbContext.Accounts.SingleOrDefault(x => x.Email == request.Email); if (account == null || !account.IsVerified || !BC.Verify(request.Password, account.PasswordHash)) { throw new AppException("Email or password is incorrect"); } // authentication successful so generate jwt and refresh tokens var jwtToken = GenerateJwtToken(account); var refreshToken = GenerateRefreshToken(ipv4Address, ipv6Address); account.RefreshTokens.Add(refreshToken); // remove old refresh tokens from account RemoveOldRefreshTokens(account); // save changes to db _dbContext.Update(account); await _dbContext.SaveChangesAsync(); var response = _mapper.Map <AuthenticateResponseDto>(account); response.JwtToken = jwtToken; response.RefreshToken = refreshToken.Token; return(response); }
public async Task <ConfigGenericItemExtentionValueDto> UpdateConfigGenericItemExtentionValueAsync(UpdateConfigGenericItemExtentionValueRequestDto request, string userName) { _logger.LogDebug($"Update existing config generic item extention value. Request : {JsonConvert.SerializeObject(request)}"); await _updateValidator.ValidateAndThrowAsync(request); var entity = await _dbContext.ConfigGenericItemExtensionValues.SingleOrDefaultAsync(x => x.GroupId == request.GroupId && x.ItemId == request.ItemId && x.ExtentionId == request.ExentionId && x.Id == request.Id); if (entity != null) { _mapper.Map(request, entity); entity.LastUpdatedDate = DateTime.Now; entity.LastUpdatedUserName = userName; _dbContext.Update(entity); await _dbContext.SaveChangesAsync(); return(_mapper.Map <ConfigGenericItemExtentionValueDto>(entity)); } _logger.LogError($"Cannot update generic config item extention value. Request : {JsonConvert.SerializeObject(request)}"); return(null); }
public async Task <PeopleInternetInformationDto> UpdatePeopleInternetInformationAsync(UpdatePeopleInternetInformationRequestDto request, string userName) { _logger.LogDebug($"Update internet information with ID {request.Id}. Request {JsonConvert.SerializeObject(request)}"); await _updateValidator.ValidateAndThrowAsync(request); var entity = await _dbContext.PeopleInternetInformations.SingleOrDefaultAsync(x => x.Id == request.Id); if (entity == null) { _logger.LogError($"Cannot find people internet information with ID {request.Id}"); return(null); } _mapper.Map(request, entity); entity.LastUpdatedDate = DateTime.Now; entity.LastUpdatedUserName = userName; _dbContext.Update(entity); await _dbContext.SaveChangesAsync(); return(_mapper.Map <PeopleInternetInformationDto>(entity)); }
public async Task <PeopleDetailedDto> UpdatePeopleAsync(UpdatePeopleRequestDto request, string userName) { _logger.LogError($"Update existing people. Request : {JsonConvert.SerializeObject(request)}"); await _updateValidator.ValidateAndThrowAsync(request); var entity = await _dbContext.Peoples.SingleOrDefaultAsync(x => x.Id == request.Id); if (entity == null) { _logger.LogError($"Cannot find people entity with Id {request.Id}"); return(null); } _mapper.Map(request, entity); entity.LastUpdatedDate = DateTime.Now; entity.LastUpdatedUserName = userName; _dbContext.Update(entity); await _dbContext.SaveChangesAsync(); return(_mapper.Map <PeopleDetailedDto>(entity)); }
public async Task <ConfigGenericItemDto> UpdateConfigGenericItemDto(UpdateConfigGenericItemRequestDto request, string userName) { _logger.LogDebug($"Updating config generic item with group Id {request.GroupId} and Id {request.Id}"); await _updateValidator.ValidateAndThrowAsync(request); var entity = await _dbContext.ConfigGenericItems.SingleOrDefaultAsync(x => x.GroupId == request.GroupId && x.Id == request.Id); if (entity != null) { _mapper.Map(request, entity); entity.LastUpdatedDate = DateTime.Now; entity.LastUpdatedUserName = userName; _dbContext.Update(entity); await _dbContext.SaveChangesAsync(); return(_mapper.Map <ConfigGenericItemDto>(entity)); } _logger.LogError($"Update config generic item, entity not found : Cannot found entity with groupId {request.GroupId} and Id {request.Id}"); return(null); }