public async Task <IActionResult> GetByFilter([FromQuery] CredentialFilter filter) { var validationResult = new CredentialFilterValidator().Validate(filter); validationResult.AddToModelState(this.ModelState, null); if (!validationResult.IsValid) { return(ValidationError()); } var page = await CredentialStore.Get(filter); if (page.IsEmpty) { return(NotFound <Credential>(filter, page.Total)); } var vmList = new List <CredentialVM>(); foreach (Credential credential in page.Items) { var newVm = new CredentialVM(credential); vmList.Add(newVm); } return(Collection <Credential>(filter, page.Total, vmList)); }
public Credential Map(CredentialFilter filter, Credential credential, CreateOrEditViewModel createOrEdit) { if (credential.Id == 0) { credential.UserId = (int)filter.User.Id; } credential.CredentialTypeId = createOrEdit.CredentialTypeId; credential.Identifier = createOrEdit.Identifier; if (!string.IsNullOrEmpty(createOrEdit.Secret)) { if (createOrEdit.ApplyPbkdf2HashingToSecret) { byte[] salt = Pbkdf2Hasher.GenerateRandomSalt(); string hash = Pbkdf2Hasher.ComputeHash(createOrEdit.Secret, salt); credential.Secret = hash; credential.Extra = Convert.ToBase64String(salt); } else { credential.Secret = createOrEdit.Secret; } } return(credential); }
public IndexViewModel Create(HttpContext httpContext, CredentialFilter filter, IEnumerable <Credential> credentials, string orderBy, int skip, int take, int total) { IStringLocalizer <IndexViewModelFactory> localizer = httpContext.GetStringLocalizer <IndexViewModelFactory>(); return(new IndexViewModel() { Filter = filter, Grid = new GridViewModelFactory().Create( httpContext, new FilterViewModelFactory().Create(httpContext, "Identifier.Contains", localizer["Identifier"]), orderBy, skip, take, total, new[] { new GridColumnViewModelFactory().Create(localizer["Credential Type"]), new GridColumnViewModelFactory().Create(localizer["Identifier"], "Identifier"), new GridColumnViewModelFactory().CreateEmpty() }, credentials.Select(c => new CredentialViewModelFactory().Create(c)), "_Credential" ) }); }