Beispiel #1
0
 public async Task<Login> AddLoginRecordAsync(Login login)
 {
   if (login == null)
     throw new ArgumentNullException("login");
   Login owner = null;
   if(login.Id==Guid.Empty)
   {
     owner = await this.FindOpenBySessionAsync(login.SessionId);
   }
   else
   {
     owner = login;//this.FindById(login.Id);
   }
   if ((owner == null))// || (owner.Result == null))
   {
     login.Id = Guid.NewGuid();
     await Task.Factory.StartNew(() =>
     {
       logins.Logins.Add(new Login(){Id=login.Id, SessionId=login.SessionId, UserId=login.UserId, LoginDate=login.LoginDate});
       //IDbConnection connection = CurrentContext.OpenConnection(CurrentContext.CurrentTransaction);
       //connection.Execute("INSERT INTO auth_Logins(Id, sessionId, UserId, LoginDate) values(@Id, @sessionId, @userId, @loginDate)", login, CurrentContext.CurrentTransaction);
     }); 
   }
   else
   {
     login.Id = owner.Id;
   }
   return login;
 }
Beispiel #2
0
    public async Task<Login> AddLoginRecordAsync(User user, String sessionId)
    {
      if (user == null)
        throw new ArgumentNullException("user");

      Login _login = new Login();
      _login.SessionId = sessionId;
      _login.UserId=user.Id;
      _login.LoginDate = System.DateTime.Now;
      _login = await AddLoginRecordAsync(_login);
      return _login;
    }
Beispiel #3
0
 public virtual Task AssignLoginToSessions(string sessionId, Login login)
 {
     if (sessionId == "")
     throw new ArgumentNullException("clientSession");
       if (login == null)
     throw new ArgumentNullException("Login");
       if (login.Id == Guid.Empty)
       {
     throw new ArgumentNullException("Login Id: " + login.Id.ToString());
       }
       return Task.Factory.StartNew(() =>
       {
     ClientSession currentSession = sessions.ClientSessions.Where(x => x.LocalSessionID==sessionId && x.LoginID==null).SingleOrDefault<ClientSession>();
     if(currentSession!=null)
     {
       currentSession.LoginID = login.Id;
     }
     //IDbConnection connection = CurrentContext.OpenConnection(CurrentContext.CurrentTransaction);
     //connection.Execute("Update auth_ClientSessions SET LoginID=@LoginID where LocalSessionID = @LocalSessionID AND LoginID IS NULL", new { LoginID = login.Id, LocalSessionID = sessionId }, CurrentContext.CurrentTransaction);
       });
 }
Beispiel #4
0
    public virtual Task LogoutAsync(Login login)
    {
      if (login == null)
        throw new ArgumentNullException("login");

      return Task.Factory.StartNew(() =>
      {
        List<Login> updateLogins = logins.Logins.Where(x => x.Id==login.Id).ToList<Login>();
        foreach (Login currentLogin in updateLogins)
        {
          login.LogoutDate = DateTime.Now;
        }
        //IDbConnection connection = CurrentContext.OpenConnection(CurrentContext.CurrentTransaction);
        //connection.Execute("Update auth_Logins SET LogoutDate = GETDATE() where Id = @loginId", new { loginId = login.Id }, CurrentContext.CurrentTransaction);
      });
    }
Beispiel #5
0
 public async Task<LoginProperty> UpdatePropertyAsync(Login login, LoginProperty loginProperty)
 {
   if (loginProperty == null)
     throw new ArgumentNullException("loginProperty");
   LoginProperty _prop = await FindPropertyByNameAsync(login, loginProperty.PropertyName);
   if (_prop == null)
   {
     loginProperty.Id = Guid.NewGuid();
     await Task.Factory.StartNew(() =>
     {
       login.LoginProperties.Add(loginProperty);
       //IDbConnection connection = CurrentContext.OpenConnection(CurrentContext.CurrentTransaction);
       //connection.Execute("INSERT INTO auth_LoginProperties(Id, LoginId, PropertyName, PropertyValue) VALUES(@Id, @LoginId, @PropertyName, @PropertyValue)", new { Id = loginProperty.Id, LoginId = loginProperty.LoginId, PropertyName = loginProperty.PropertyName, PropertyValue = loginProperty.PropertyValue }, CurrentContext.CurrentTransaction);
     });
   }
   else
   {
     //loginProperty.Id = _prop.Id;
     await Task.Factory.StartNew(() =>
     {
       _prop.PropertyValue = loginProperty.PropertyValue;
     //  IDbConnection connection = CurrentContext.OpenConnection(CurrentContext.CurrentTransaction);
     //  connection.Execute("Update auth_LoginProperties SET PropertyName=@PropertyName, PropertyValue=@PropertyValue WHERE Id=PropertyId", new { PropertyName = loginProperty.PropertyName, PropertyValue = loginProperty.PropertyValue, PropertyId = _prop.Id }, CurrentContext.CurrentTransaction);
     });
   }
   return loginProperty;
 }
Beispiel #6
0
    public virtual Task<LoginProperty> FindPropertyByNameAsync(Login login, string propertyName)
    {
      if (login == null)
        throw new ArgumentNullException("login");

      if (propertyName == "")
        throw new ArgumentNullException("propertyName");

      return Task.Factory.StartNew(() =>
      {
        return login.LoginProperties.Where(x => x.PropertyName == propertyName).SingleOrDefault<LoginProperty>();
        //using (IDbConnection connection = CurrentContext.OpenConnection())
        //  return connection.Query<LoginProperty>("select DISTINCT * FROM auth_LoginProperties WHERE LoginId=@LoginId AND PropertyName LIKE @PropertyName", new { LoginId = loginId, PropertyName = propertyName }).SingleOrDefault();
      });
    }