public Credential Map(CreateOrEditViewModel createOrEdit)
        {
            Credential credential = new Credential();

              if (createOrEdit.Id != null)
            credential = this.handler.Storage.GetRepository<ICredentialRepository>().WithKey((int)createOrEdit.Id);

              else credential.UserId = createOrEdit.UserId;

              credential.CredentialTypeId = createOrEdit.CredentialTypeId;
              credential.Identifier = createOrEdit.Identifier;

              if (!string.IsNullOrEmpty(createOrEdit.Secret))
            credential.Secret = createOrEdit.ApplyMd5HashingToSecret ? MD5Hasher.ComputeHash(createOrEdit.Secret) : createOrEdit.Secret;

              return credential;
        }
        public IActionResult CreateOrEdit(CreateOrEditViewModel createOrEdit)
        {
            if (this.ModelState.IsValid)
              {
            Credential credential = new CreateOrEditViewModelMapper(this).Map(createOrEdit);

            if (createOrEdit.Id == null)
              this.Storage.GetRepository<ICredentialRepository>().Create(credential);

            else this.Storage.GetRepository<ICredentialRepository>().Edit(credential);

            this.Storage.Save();
            return this.Redirect(this.Request.CombineUrl("/backend/credentials"));
              }

              return this.CreateRedirectToSelfResult();
        }
        public Credential Map(CreateOrEditViewModel createOrEdit)
        {
            Credential credential = new Credential();

            if (createOrEdit.Id != null)
            {
                credential = this.RequestHandler.Storage.GetRepository <ICredentialRepository>().WithKey((int)createOrEdit.Id);
            }

            else
            {
                credential.UserId = createOrEdit.UserId;
            }

            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 Credential Map(CreateOrEditViewModel createOrEdit)
        {
            Credential credential = new Credential();

            if (createOrEdit.Id != null)
            {
                credential = this.handler.Storage.GetRepository <ICredentialRepository>().WithKey((int)createOrEdit.Id);
            }

            else
            {
                credential.UserId = createOrEdit.UserId;
            }

            credential.CredentialTypeId = createOrEdit.CredentialTypeId;
            credential.Identifier       = createOrEdit.Identifier;

            if (!string.IsNullOrEmpty(createOrEdit.Secret))
            {
                credential.Secret = createOrEdit.ApplyMd5HashingToSecret ? MD5Hasher.ComputeHash(createOrEdit.Secret) : createOrEdit.Secret;
            }

            return(credential);
        }