コード例 #1
0
 public bool Create(Registrate reg)
 {
     using (var connection = new SqlConnection(connectionString))
     {
         var addReg = connection.CreateCommand();
         addReg.CommandText = $"INSERT INTO dbo.Authentication (Login, Password, RoleId) VALUES (@LOG, @PASS, @ROLE)";
         addReg.Parameters.AddWithValue("@LOG", reg.Login);
         addReg.Parameters.AddWithValue("@PASS", reg.Password);
         addReg.Parameters.AddWithValue("@ROLE", reg.RoleId);
         connection.Open();
         var result = addReg.ExecuteNonQuery();
         if (result == 0)
         {
             return(false);
         }
         return(true);
     }
 }
コード例 #2
0
 public Registrate Get(string login)
 {
     using (var connection = new SqlConnection(connectionString))
     {
         Registrate myReg   = null;
         var        command = connection.CreateCommand();
         command.CommandText = "SELECT Id, Password, RoleId FROM dbo.Authentication WHERE Login = @LOG";
         command.Parameters.AddWithValue("@LOG", login);
         connection.Open();
         using (var reader = command.ExecuteReader())
         {
             while (reader.Read())
             {
                 myReg = new Registrate(login, (string)reader["Password"], (int)reader["RoleId"]);
             }
         }
         return(myReg);
     }
 }
コード例 #3
0
 public bool Create(Registrate reg)
 {
     return(DAL.Create(reg));
 }