Advertisement
Guest User

Untitled

a guest
May 1st, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.27 KB | None | 0 0
  1. public ISession Login(string username, string password) {
  2. if (username == null)
  3. throw new ArgumentNullException("username", "il nome utente non deve essere null");
  4. if (password == null)
  5. throw new ArgumentNullException("password", "la passsword non deve essere null");
  6. Context.Refresh(RefreshMode.StoreWins, this);
  7. if (this.EntityState == System.Data.EntityState.Detached)
  8. throw new InvalidOperationException("il sito � stato cancellato");
  9. /*using (var context = new DatabaseEntities(connectionString))
  10. {*/
  11. /* foreach (var session in Sessions){
  12. if(session.User.username == username && )
  13. }*/
  14. //Context.Refresh(RefreshMode.StoreWins, Users);
  15. var existingUsers = from user in Users
  16. where /*user.Site == this
  17. &&*/ user.Username == username
  18. && user.password == password
  19. select user;
  20. if (!existingUsers.Any())
  21. return null;
  22. User myUser = existingUsers.First();
  23. /*var existingSessions = from session in Sessions
  24. where session.User.Username ==
  25. && session.User.password == password
  26. select session;*/
  27.  
  28. var validSessions = from session in myUser.Sessions
  29. where session.IsValid()
  30. select session;
  31. if (validSessions.Any())
  32. return Sessions.First();
  33. Session newsession = Session.CreateSession(0);
  34. newsession.User = myUser;
  35. //myUser.Sessions.Add(newsession);
  36. newsession.Site = this;
  37. newsession.AlarmClock = this.AlarmClock;
  38. newsession.Context = this.Context;
  39. newsession.Starting = this.AlarmClock.Now;
  40. newsession.Time = new TimeSpan(0, 0, SessionExpirationInSeconds);
  41. //this.Sessions.Add(newsession);
  42. Context.AddToSessions(newsession);
  43. Context.SaveChanges();
  44. return newsession;
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement