Link to home
Start Free TrialLog in
Avatar of sunny-j
sunny-j

asked on

Help with linking queries using c#

Greetings Experts,

Please could you guide on how I can display users records after login.

@{
 

// Initialize general page variables
var authenticatedUser = "";
var authenticatedUserFirstName = "";
var authenticatedUserLastName = "";
var authenticatedUseremail ="";
if (WebSecurity.IsAuthenticated) {
authenticatedUser = WebSecurity.CurrentUserName;
var db = Database.Open("Db2");
var UserData = db.QuerySingle("Select a.Email1, a.FirstName, a.LastName from pro.Worker a inner join StarterSite.dbo.UserProfile b on b.Email = a.Email1 WHERE LOWER(Email) = LOWER(@0)", authenticatedUser);
  
authenticatedUserFirstName = UserData.FirstName;
authenticatedUserLastName = UserData.LastName;
//authenticatedUseremail = UserData.Email;

    }
   
}

<!DOCTYPE html>

<html lang="en">
    <head>
        <meta charset="utf-8" />
        <title></title>
    </head>
    <body>
        @if (WebSecurity.IsAuthenticated) {
                            <p>
                                Hello, <a class="username" href="~/Account/PasswordReset" title="Change password"> @authenticatedUserFirstName  </a>!
                                <a href="~/Account/Logout">Logout</a>
                                
             
                            </p>
                                }
      
    
    </body>

</html>
                                  

Open in new window


 


 At this stage, I seem to be referencing the right user - now I would like to display tables and additional pages with results of queries related to their profile. Can you please point out how I do this. I am currently using the razor syntax in c# so appreciate sample code in this language as not proficient enough to convert.

 To give an example, this is what I would like to do..


Hello @user,
 Please find your profile information below
 Your Full Name @name
 Your email @email

 Please find current bookings below.. etc., ....


 Query from same database but different tables ( I can do the queries but struggling to see how they link up here so properly linking. )

 Thank you in anticipation of solutions. Kind regards. SJ
Avatar of Bob Learned
Bob Learned
Flag of United States of America image

You have this query:

Select a.Email1, a.FirstName, a.LastName from pro.Worker a
      inner join StarterSite.dbo.UserProfile b on b.Email = a.Email1
      WHERE LOWER(Email) = LOWER(@0)", authenticatedUser);

Are the profile properties to display pulled in that query?  If so, then my suggestion would be to pass in the UserData as the model to the view, and then you can reference the property like this:

@Model.FullName
@Model.EmailAddress
...
Avatar of sunny-j
sunny-j

ASKER

Dear Bob, really appreciate your swift response. I think I am definitely overcomplicated what I am trying to do. Do you think it will help to try and do this without authentication in place just to get it working properly. I am having trouble getting my head around how to pass the parameter and display anything other than the authentication fields.

Also, I can't seem to make @Model work in WebMatrix. Any further help you can offer will be most welcome.  

Kindest regards. SJ
ASKER CERTIFIED SOLUTION
Avatar of Bob Learned
Bob Learned
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of sunny-j

ASKER

perfect, thanks Bob, I have gone back to the drawing board and started over in MCV rather than continue with WebMatrix. Thanks for your help. Kind regards. SJ