Ejemplo n.º 1
0
        public UserAccount CreateUserAccount(UserAccount userAccount)
        {
            userAccount.DateCreated = DateTime.Now;

            userAccount.Id = Guid.NewGuid().ToString();
            if (!string.IsNullOrEmpty(userAccount.UserPwdString))
            {
                userAccount.UserPwdHash = c.encrypt(userAccount.UserPwdString);
            }

            var tQUery = generateInserQuery(userAccount);

            DBContext.ExecuteQuery(tQUery.Query.ToString(), tQUery.Parameters);

            return(userAccount);
        }
Ejemplo n.º 2
0
        public void UpdateUserAccount(UserAccount userAccountChanges)
        {
            cryptor c = new cryptor("JOJO");

            var objUser = userAccountChanges;

            objUser.TimeStamp   = DateTime.Now;
            objUser.UserPwdHash = c.encrypt(objUser.UserPwdString);

            List <ParameterInfo> parameters = new List <ParameterInfo>();

            parameters.Add(new ParameterInfo {
                ParameterName = nameof(objUser.Id), ParameterValue = objUser.Id, ParameterDbType = System.Data.DbType.String
            });
            parameters.Add(new ParameterInfo {
                ParameterName = nameof(objUser.UserName), ParameterValue = objUser.UserName
            });
            parameters.Add(new ParameterInfo {
                ParameterName = nameof(objUser.UserPwdHash), ParameterValue = objUser.UserPwdHash
            });
            parameters.Add(new ParameterInfo {
                ParameterName = nameof(objUser.LastName), ParameterValue = objUser.LastName.ToUpper()
            });
            parameters.Add(new ParameterInfo {
                ParameterName = nameof(objUser.MiddleName), ParameterValue = objUser.MiddleName.ToUpper()
            });
            parameters.Add(new ParameterInfo {
                ParameterName = nameof(objUser.FirstName), ParameterValue = objUser.FirstName.ToUpper()
            });
            parameters.Add(new ParameterInfo {
                ParameterName = nameof(objUser.NameSuffix), ParameterValue = objUser.NameSuffix.ToUpper()
            });
            parameters.Add(new ParameterInfo {
                ParameterName = nameof(objUser.PhoneNumber), ParameterValue = objUser.PhoneNumber
            });
            parameters.Add(new ParameterInfo {
                ParameterName = nameof(objUser.EmailAddress), ParameterValue = objUser.EmailAddress
            });
            parameters.Add(new ParameterInfo {
                ParameterName = nameof(objUser.Position), ParameterValue = objUser.Position.ToUpper()
            });
            parameters.Add(new ParameterInfo {
                ParameterName = nameof(objUser.Department), ParameterValue = objUser.Department.ToUpper()
            });
            //parameters.Add(new ParameterInfo { ParameterName = nameof(objUser.DateCreated), ParameterValue = objUser.DateCreated });
            //parameters.Add(new ParameterInfo { ParameterName = nameof(objUser.RegisteredBy), ParameterValue = objUser.RegisteredBy });
            parameters.Add(new ParameterInfo {
                ParameterName = nameof(objUser.ModifiedBy), ParameterValue = objUser.ModifiedBy
            });
            parameters.Add(new ParameterInfo {
                ParameterName = nameof(objUser.TimeStamp), ParameterValue = objUser.TimeStamp
            });
            // parameters.Add(new ParameterInfo { ParameterName = nameof(objUser.Status), ParameterValue = objUser.Status, ParameterDbType = System.Data.DbType.String });
            //parameters.Add(new ParameterInfo { ParameterName = nameof(objUser.AccessFailedCount), ParameterValue = 0 });


            StringBuilder str = new StringBuilder();

            str.AppendLine(" UPDATE [dbo].[UserAccounts] ");
            str.AppendLine($"    SET {nameof(objUser.UserName)} = @{nameof(objUser.UserName)}, ");
            str.AppendLine($"     {nameof(objUser.UserPwdHash)} = @{nameof(objUser.UserPwdHash)}, ");
            str.AppendLine($"     {nameof(objUser.LastName)} = @{nameof(objUser.LastName)}, ");
            str.AppendLine($"     {nameof(objUser.MiddleName)} = @{nameof(objUser.MiddleName)}, ");
            str.AppendLine($"     {nameof(objUser.FirstName)} = @{nameof(objUser.FirstName)}, ");
            str.AppendLine($"     {nameof(objUser.NameSuffix)} = @{nameof(objUser.NameSuffix)}, ");
            str.AppendLine($"     {nameof(objUser.Department)} = @{nameof(objUser.Department)}, ");
            str.AppendLine($"     {nameof(objUser.Position)} = @{nameof(objUser.Position)}, ");
            str.AppendLine($"     {nameof(objUser.EmailAddress)} = @{nameof(objUser.EmailAddress)}, ");
            str.AppendLine($"     {nameof(objUser.PhoneNumber)} = @{nameof(objUser.PhoneNumber)}, ");
            str.AppendLine($"     {nameof(objUser.ModifiedBy)} = @{nameof(objUser.ModifiedBy)}, ");
            str.AppendLine($"     {nameof(objUser.TimeStamp)} = @{nameof(objUser.TimeStamp)} ");
            str.AppendLine("  WHERE Id = @Id ");

            int success = DBContext.ExecuteQuery(str.ToString(), parameters: parameters, commandType: System.Data.CommandType.Text);
        }