Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public ISession Login(string username, string password) {
- if (username == null)
- throw new ArgumentNullException("username", "il nome utente non deve essere null");
- if (password == null)
- throw new ArgumentNullException("password", "la passsword non deve essere null");
- Context.Refresh(RefreshMode.StoreWins, this);
- if (this.EntityState == System.Data.EntityState.Detached)
- throw new InvalidOperationException("il sito � stato cancellato");
- /*using (var context = new DatabaseEntities(connectionString))
- {*/
- /* foreach (var session in Sessions){
- if(session.User.username == username && )
- }*/
- //Context.Refresh(RefreshMode.StoreWins, Users);
- var existingUsers = from user in Users
- where /*user.Site == this
- &&*/ user.Username == username
- && user.password == password
- select user;
- if (!existingUsers.Any())
- return null;
- User myUser = existingUsers.First();
- /*var existingSessions = from session in Sessions
- where session.User.Username ==
- && session.User.password == password
- select session;*/
- var validSessions = from session in myUser.Sessions
- where session.IsValid()
- select session;
- if (validSessions.Any())
- return Sessions.First();
- Session newsession = Session.CreateSession(0);
- newsession.User = myUser;
- //myUser.Sessions.Add(newsession);
- newsession.Site = this;
- newsession.AlarmClock = this.AlarmClock;
- newsession.Context = this.Context;
- newsession.Starting = this.AlarmClock.Now;
- newsession.Time = new TimeSpan(0, 0, SessionExpirationInSeconds);
- //this.Sessions.Add(newsession);
- Context.AddToSessions(newsession);
- Context.SaveChanges();
- return newsession;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement