Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //AUTH
- exports.getUserID = function () {
- id;
- request
- .get('/user/userid')
- .send('test')
- .end(function (err, res) {
- if (!err) {
- id = res.body.id;
- console.log(res.body);
- } else {
- console.log('error');
- }
- });
- return id;
- };
- //CONTROLLER
- /* Metodas, skirtas pasiekti vartotojo ID per SQL užklausą */
- public int userID(string username)
- {
- Models.User user = new Models.User();
- return user.userID(username);
- }
- //MODEL USER.CS
- public int userID(string _username)
- {
- int id = 0;
- using (var cn = new SqlConnection(@"Data Source=slothfantasydb.database.windows.net;Initial Catalog=SlothDb;Persist Security Info=True;User ID=SlothfantasyDb;Password=123Projektas"))
- {
- string _sql = @"SELECT * FROM [dbo].[User] WHERE username='test'";
- var cmd = new SqlCommand(_sql, cn);
- /*cmd.Parameters
- .Add(new SqlParameter("@u", SqlDbType.NVarChar))
- .Value = _username;*/
- cn.Open();
- var reader = cmd.ExecuteReader();
- while (reader.Read())
- {
- id = int.Parse(reader.GetValue(0).ToString());
- }
- cn.Close();
- }
- return id;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement