SHARE
TWEET

Untitled

a guest Jun 18th, 2019 102 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Check Userlogin if it contains adminuser1 as username, if not, add adminuser1 with password xyz.
  2.  
  3. UserLogin login = new UserLogin();  
  4. login.username="adminuser1";  
  5. login.password="xyz";  
  6. context.UserLogins.Add(login);  
  7. context.SaveChanges();  
  8.  
  9. // query again from database to get the userid  
  10. Userlogin user = context.UserLogins.Single(l=>(l.username=="adminuser1")&& (l.password=="xyz"));  
  11. int userid = user.userid;  
  12. UserRole admin = new UserRole();  
  13. admin.userid = userid;  
  14. admin.role="admin";  
  15. context.UserRoles.Add(admin);  
  16. context.SaveChanges();
  17.      
  18. UserLogin login = new UserLogin();  
  19. login.username="adminuser1";  
  20. login.password="xyz";  
  21. UserLogin user = context.UserLogins.Add(login);  
  22. UserRole admin = new UserRole();  
  23. admin.userid = user.userid;  
  24. admin.role="admin";  
  25. context.UserRoles.Add(admin);  
  26. context.SaveChanges();
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top