Esempio n. 1
0
        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 <ConfigGenericGroupDto> AddNewConfigGenericGroupAsync(AddConfigGenericGroupDto request, string userName)
        {
            await _addConfigGenericGroupValidator.ValidateAndThrowAsync(request);

            var entity = _mapper.Map <ConfigGenericGroup>(request);

            entity.CreatedDate         = DateTime.Now;
            entity.LastUpdatedUserName = userName;

            var result = _dbContext.ConfigGenericGroups.Add(entity).Entity;
            await _dbContext.SaveChangesAsync();

            return(_mapper.Map <ConfigGenericGroupDto>(result));
        }
        public async Task <SystemDataTypeDto> AddSystemDataTypeAsync(AddSystemDataTypeRequestDto request, string userName)
        {
            _logger.LogDebug($"Add new system data type. Request : {JsonConvert.SerializeObject(request)}");
            await _addValidator.ValidateAndThrowAsync(request);

            var entity = _mapper.Map <SystemDataType>(request);

            entity.CreatedDate         = DateTime.Now;
            entity.LastUpdatedUserName = userName;

            _dbContext.SystemDataTypes.Add(entity);
            await _dbContext.SaveChangesAsync();

            return(_mapper.Map <SystemDataTypeDto>(entity));
        }
        public async Task <PeopleInternetInformationDto> AddPeopleInternetInformationAsync(AddPeopleInternetInformationRequestDto request, string userName)
        {
            _logger.LogDebug($"Adding new internet information for people with ID {request.PeopleId}. Request {JsonConvert.SerializeObject(request)}");

            await _addValidator.ValidateAndThrowAsync(request);

            var entity = _mapper.Map <PeopleInternetInformation>(request);

            entity.IsObsolete          = false;
            entity.CreatedDate         = DateTime.Now;
            entity.LastUpdatedUserName = userName;

            _dbContext.PeopleInternetInformations.Add(entity);
            await _dbContext.SaveChangesAsync();

            return(_mapper.Map <PeopleInternetInformationDto>(entity));
        }
Esempio n. 5
0
        public async Task <ConfigGenericItemDto> AddNewConfigGenericItemAsync(AddConfigGenericItemRequestDto request, string userName)
        {
            _logger.LogDebug($"Adding new config generic item : {JsonConvert.SerializeObject(request)}");
            await _addConfigGenericItemValidator.ValidateAndThrowAsync(request);

            var entity = _mapper.Map <ConfigGenericItem>(request);

            entity.Id = await GetNextIdHelper.GetNextIdConfigItemAsync(request, _dbContext);

            entity.CreatedDate         = DateTime.Now;
            entity.LastUpdatedUserName = userName;

            _dbContext.ConfigGenericItems.Add(entity);
            await _dbContext.SaveChangesAsync();

            return(_mapper.Map <ConfigGenericItemDto>(entity));
        }
Esempio n. 6
0
        public async Task <PeopleDetailedDto> AddPeopleAsync(AddPeopleRequestDto request, string userName)
        {
            _logger.LogDebug($"Add new people. Request : {JsonConvert.SerializeObject(request)}");

            await _addValidator.ValidateAndThrowAsync(request);

            var entity = _mapper.Map <People>(request);

            entity.Deceased            = false;
            entity.IsActive            = true;
            entity.CreatedDate         = DateTime.Now;
            entity.LastUpdatedUserName = userName;

            _dbContext.Peoples.Add(entity);
            await _dbContext.SaveChangesAsync();

            return(_mapper.Map <PeopleDetailedDto>(entity));
        }
Esempio n. 7
0
        public async Task <ColonyDto> AddColonyAsync(AddColonyRequestDto request, string fullName)
        {
            _logger.LogDebug($"Add new colony. Request {JsonConvert.SerializeObject(request)}");
            await _addValidator.ValidateAndThrowAsync(request);

            var entity = _mapper.Map <Colony>(request);

            entity.CreatedDate         = DateTime.Now;
            entity.LastUpdatedUserName = fullName;

            _dbContext.Add(entity);
            await _dbContext.SaveChangesAsync();

            return(_mapper.Map <ColonyDto>(entity));
        }