예제 #1
0
 public static void ValidateUser(IEnumerable <User> users)
 {
     foreach (var user in users)
     {
         if (!Regex.IsMatch(user.Email, emailRegex, RegexOptions.IgnoreCase))
         {
             ValidationResult.AddValidation(user.Row, invalidEmailFormatMessage);
         }
         if (!Regex.IsMatch(user.LoginName, loginNameRegex))
         {
             ValidationResult.AddValidation(user.Row, invalidLoginNameFormatMessage);
         }
         if (!Regex.IsMatch(user.MobileNumber.ToString(), mobileNumberRegex))
         {
             ValidationResult.AddValidation(user.Row, invalidMobileNumberMessage);
         }
     }
 }
예제 #2
0
        //private static DataSet GetDataSet(string worksheetName)
        //{
        //    String sExcelConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + FileName + ";Extended Properties=Excel 12.0";
        //    //String sExcelConnectionString = "Provider=Microsoft.Jet.Oledb.4.0;Data Source=" + filename + ";Extended Properties=Excel 8.0;Mode=ReadWrite|Share Deny None;Persist Security Info=False";
        //    OleDbConnection OleDbConn = new OleDbConnection(sExcelConnectionString);

        //    OleDbConn.Open();
        //    OleDbCommand OleDbCmd = new OleDbCommand(("SELECT * FROM " + worksheetName), OleDbConn);

        //    DataSet dataSet = new DataSet();

        //    OleDbDataAdapter sda = new OleDbDataAdapter(OleDbCmd);
        //    sda.Fill(dataSet);
        //    OleDbConn.Close();
        //    return dataSet;
        //}

        private static IEnumerable <User> FillUser(DataTable userTable)
        {
            List <User> users    = new List <User>();
            var         rowCount = 0;

            foreach (DataRow row in userTable.Rows)
            {
                if (row.ItemArray.All(x => x == null || (x != null && string.IsNullOrWhiteSpace(x.ToString()))))
                {
                    continue;
                }

                rowCount++;

                try
                {
                    users.Add(new User
                    {
                        FirstName           = row.Field <string>("FirstName"),
                        LastName            = row.Field <string>("LastName"),
                        MobileNumber        = Convert.ToInt64(row["MobileNumber"]),
                        Password            = row.Field <string>("Password"),
                        LoginName           = row.Field <string>("LoginName"),
                        ActivationDate      = row.Field <DateTime?>("ActivationDate"),
                        DeactivationDate    = row.Field <DateTime?>("DeactivationDate"),
                        Email               = row.Field <string>("Email"),
                        IsBlocked           = row.Field <bool>("IsBlocked"),
                        ForcePasswordReset  = row.Field <bool>("ForcePasswordReset"),
                        LoginBlockedTime    = row.Field <DateTime?>("LoginBlockedTime"),
                        LoginFailureCounter = Convert.ToInt32(row["LoginFailureCounter"]),
                        Row = rowCount
                              //Status = row.Field<StatusValues?>("Status") ?? StatusValues.Unknown
                    });
                }
                catch (InvalidCastException ex)
                {
                    ValidationResult.AddValidation(rowCount, ex.Message);
                    ValidationResult.AddValidation(rowCount, "Please check the date formats of this row.");
                }
            }

            return(users);
        }