public DeployCredentials CreateCredentials(string domain, string userName, string encrytpedPassword)
		{
            if(string.IsNullOrEmpty(domain))
            {
                throw new ArgumentNullException("domain");
            }
            if(string.IsNullOrEmpty(userName))
            {
                throw new ArgumentNullException("userName");
            }
            if(string.IsNullOrEmpty(encrytpedPassword))
            {
                throw new ArgumentNullException("encrytpedPassword");
            }
			//string id = FormatId(userName, domain);
			var existingItem = _documentSession.QueryNoCacheNotStale<DeployCredentials>().FirstOrDefault(i=>i.UserName == userName && i.Domain == domain);//.Where(i=>i.Domain == domain).Where(i=>i.UserName == i.UserName).FirstOrDefault();
			if(existingItem != null)
			{
				throw new ArgumentException(string.Format("UserName already exists: {0}\\{1}", domain, userName));
			}
			var item = new DeployCredentials
			{
				Id = Guid.NewGuid().ToString(),
				Domain = domain,
				UserName = userName,
				EncryptedPassword = encrytpedPassword,
				CreatedByUserName = _userIdentity.UserName,
				CreatedDateTimeUtc = DateTime.UtcNow,
				UpdatedByUserName = _userIdentity.UserName,
				UpdatedDateTimeUtc = DateTime.UtcNow
			};
			_documentSession.Store(item);
			_documentSession.SaveChanges();
			return item;
		}
		public SecureString DecryptPasswordSecure(DeployCredentials credentials)
		{
			var returnValue = new SecureString();
			foreach (var c in _encrypterator.Decrypt(credentials.UserName, credentials.EncryptedPassword))
			{
				returnValue.AppendChar(c);
			}
			return returnValue;
		}
		public string DecryptPassword(DeployCredentials credentials)
		{
			return _encrypterator.Decrypt(credentials.UserName, credentials.EncryptedPassword);
		}
 public DeployCredentials CreateCredentials(string domain, string userName, string encrytpedPassword)
 {
     if(string.IsNullOrEmpty(domain))
     {
         throw new ArgumentNullException("domain");
     }
     if(string.IsNullOrEmpty(userName))
     {
         throw new ArgumentNullException("userName");
     }
     if(string.IsNullOrEmpty(encrytpedPassword))
     {
         throw new ArgumentNullException("encryptedPassword");
     }
     CheckForDuplicate(null, domain, userName);
     var item = new DeployCredentials
     {
         Id = Guid.NewGuid().ToString(),
         Domain = domain,
         UserName = userName,
         EncryptedPassword = encrytpedPassword,
         CreatedByUserName = _userIdentity.UserName,
         CreatedDateTimeUtc = DateTime.UtcNow,
         UpdatedByUserName = _userIdentity.UserName,
         UpdatedDateTimeUtc = DateTime.UtcNow
     };
     var sql = PetaPoco.Sql.Builder
                 .Append("INSERT INTO DeployCredential (ID, Domain, UserName, EncryptedPassword, CreatedByUserName, CreatedDateTimeUtc, UpdatedByUserName, UpdatedDateTimeUtc)")
                 .Append("VALUES (@Id, @Domain, @UserName, @EncryptedPassword, @CreatedByUserName, @CreatedDateTimeUtc, @UpdatedByUserName, @UpdatedDateTimeUtc)", item);
     using(var db = _sqlConnectionInfo.GetDB())
     {  
         db.Execute(sql);
     }
     return this.GetCredentials(item.Id);
 }
 public DeployCredentials UpdateCredentials(string credentialsId, string domain, string userName, string encrytpedPassword)
 {
     if(string.IsNullOrEmpty(domain))
     { 
         throw new ArgumentNullException("domain");
     }
     if(string.IsNullOrEmpty(userName))
     {
         throw new ArgumentNullException("userName");
     }
     if(string.IsNullOrEmpty(encrytpedPassword))
     {
         throw new ArgumentNullException("encrytpedPassword");
     }
     VerifyExists(credentialsId);
     CheckForDuplicate(credentialsId, domain, userName);
     var item = new DeployCredentials
     {
         Id = credentialsId,
         Domain = domain,
         UserName = userName,
         EncryptedPassword = encrytpedPassword,
         UpdatedByUserName = _userIdentity.UserName,
         UpdatedDateTimeUtc = DateTime.UtcNow
     };
     var sql = PetaPoco.Sql.Builder
                 .Append("UPDATE DeployCredential")
                 .Append("SET Domain = @Domain, UserName=@UserName, EncryptedPassword=@EncryptedPassword, UpdatedByUserName=@UpdatedByUserName, UpdatedDateTimeUtc=@UpdatedDateTimeUtc", item)
                 .Append("WHERE ID=@0", credentialsId);
     using(var db = _sqlConnectionInfo.GetDB())
     {
         db.Execute(sql);
     }
     return this.GetCredentials(credentialsId);
 }