public ActionResult ModifyAccount(User user) { if (user != null) { var connetionString = Properties.Settings.Default.dbConnectionString; var sql = "Update AspNetUsers Set Email = '" + user.Email + "', PhoneNumber = '" + user.PhoneNumber + "' Where Id = '" + User.Identity.GetUserId() + "'"; var cnn = new SqlConnection(connetionString); try { cnn.Open(); var command = new SqlCommand(sql, cnn); command.ExecuteNonQuery(); command.Dispose(); cnn.Close(); } catch (Exception ex) { } } return View("Manage", user); }
private User GetUserProfil() { SqlConnection cnn = null; string connetionString = Properties.Settings.Default.dbConnectionString; User user = null; string sql = "SELECT u.UserName, u.Email, u.PhoneNumber " + "FROM AspNetUsers u " + "Where u.Id = '" + User.Identity.GetUserId() + "'"; cnn = new SqlConnection(connetionString); try { cnn.Open(); var command = new SqlCommand(sql, cnn); var dataReader = command.ExecuteReader(); while (dataReader.Read()) { user = new User { NomUtil = dataReader.GetValue(0).ToString(), Email = dataReader.GetValue(1).ToString(), PhoneNumber = dataReader.GetValue(2).ToString() }; } dataReader.Close(); command.Dispose(); cnn.Close(); } catch (Exception ex) { } return user; }