public static User GetUserInfo(string username) { string connectionstring = ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString; User user = new User(); SqlConnection dbconnection = new SqlConnection(connectionstring); SqlCommand cmd = new SqlCommand(); cmd.Parameters.AddWithValue("@UserName", username); SqlDataReader reader; cmd.CommandText = "GetUserDetails"; cmd.CommandType = CommandType.StoredProcedure; cmd.Connection = dbconnection; dbconnection.Open(); reader = cmd.ExecuteReader(); if (reader.Read()) { user.UserID = reader.GetInt32(0); user.UserFirstName = reader.GetString(1); user.UserLastName = reader.GetString(2); user.Active = reader.GetBoolean(3); } dbconnection.Dispose(); dbconnection.Close(); return user; }
public ActionResult EditUserInfo(User user) { var db = new BandStudentDBEntities(); if (ModelState.IsValid) { db.UpdateUserRecord(user.UserID, user.UserName, user.UserFirstName, user.UserLastName, user.Active); db.SaveChanges(); } return RedirectToAction("Index"); }