public async Task <TrimUriModel> TrimUrlAsync( string address ) { if (address == null) { throw new ArgumentException(); } address = address.Trim(); if (string.IsNullOrEmpty(address)) { throw new ArgumentException(); } address = address.ToLower(); if (!Uri.TryCreate(address, UriKind.Absolute, out Uri uriResult)) { throw new ArgumentException(); } var result = new TrimUriModel(address); var find = await DbContext .TrimUrls .Where(x => x.Address == address) .FirstOrDefaultAsync(); if (find != null) { result.Trimmed = UriPrefix + find.HashCode; return(result); } var key = ""; do { key = HasherService.Generate(UriSuffixLength); var conflict = await DbContext .TrimUrls .AnyAsync(x => x.HashCode.ToLower() == key); if (!conflict) { break; } }while (true); var append = new TrimUrlEntity { Address = address, HashCode = key, }; DbContext.TrimUrls.Add(append); await DbContext.SaveChangesAsync(); result.Trimmed = UriPrefix + key; return(result); }
public Usuario(UsuarioDTO dto, HasherService service) { this.Email = dto.Email; this.Nome = dto.Nome; this.Senha = service.HashPassword(dto.Senha); }
public Usuario ToEntity(HasherService hasherService) { return(new Usuario(this, hasherService)); }
public UsuarioController(ITokenService tokenService) { _tokenService = tokenService; _hasherService = new HasherService(); }