public void InsertLog(string userId)
        {
            try
            {
                _billCollDataContext = new BillCollDataContext();
                TraceLog trLog = new TraceLog();
                trLog.UserId    = int.Parse(userId);
                trLog.LoginTime = DateTime.Now;
                _billCollDataContext.TraceLogs.InsertOnSubmit(trLog);
                User user = _billCollDataContext.Users.Single(u => u.UserId == int.Parse(userId));
                user.isLoggedIn = true;
                _billCollDataContext.SubmitChanges();
                //if (_connectionString.Equals(string.Empty) != true)
                //{
                //_databaseManager.OpenDatabaseConnection();

                //string sqlCommand = " INSERT INTO TraceLog (UserId,LoginTime) VALUES ("+userId+",GETDATE())";
                //_databaseManager.ExcecuteCommand(sqlCommand);
                //sqlCommand = " Update Users set isLoggedIn=1 where UserId="+userId;
                //_databaseManager.ExcecuteCommand(sqlCommand);
                //}
            }
            catch (Exception exception)
            {
                throw exception;
            }
            finally
            {
                //_databaseManager.CloseDatabaseConnection();
            }
        }
        public bool UpdateLog(string userId)
        {
            try
            {
                int logId = (from trLogs in _billCollDataContext.TraceLogs
                             where trLogs.UserId == int.Parse(userId)
                             select trLogs.LogId).Max();

                TraceLog trLog = _billCollDataContext.TraceLogs.Single(t => t.LogId == logId);
                trLog.LogoutTime = DateTime.Now;
                _billCollDataContext.SubmitChanges();
                return(true);
                //if(_connectionString.Equals(string.Empty)!=true)
                //{
                //    _databaseManager.OpenDatabaseConnection();
                //    string sqlQuerey="select MAX(LogId) from TraceLog where userId="+userId;
                //    string logId=_databaseManager.GetSingleString(sqlQuerey);
                //    string sqlCommand = " Update TraceLog set LogoutTime =GETDATE() where LogId="+logId;
                //    _databaseManager.ExcecuteCommand(sqlCommand);
                //    sqlCommand = " Update Users set isLoggedIn=0 where UserId="+userId;
                //    _databaseManager.ExcecuteCommand(sqlCommand);

                //    return true;
                //}
            }catch (Exception exception)
            {
                throw exception;
            }
            finally
            {
                //_databaseManager.CloseDatabaseConnection();
            }

            return(false);
        }
Beispiel #3
0
 public void CreteNewUser(User user)
 {
     try
     {
         _databaseManager.SetConnectionString = _connectionString;
         _databaseManager.OpenDatabaseConnection();
         user.Password        = encryptionDecriptionManager.ComputeHash(user.Password, new byte[user.Password.Length]);
         _billCollDataContext = new BillCollDataContext();
         _billCollDataContext.Users.InsertOnSubmit(user);
         _billCollDataContext.SubmitChanges();
     }
     catch (Exception exception)
     {
         throw exception;
     }
     finally
     {
         _databaseManager.CloseDatabaseConnection();
     }
 }
Beispiel #4
0
        public void ChangePassword(string userId, string oldPassword, string newPassword)
        {
            try
            {
                _billCollDataContext = new BillCollDataContext();
                if (!_connectionString.Equals(String.Empty))
                {
                    newPassword = encryptionDecriptionManager.ComputeHash(newPassword, new byte[newPassword.Length]);
                    oldPassword = encryptionDecriptionManager.ComputeHash(oldPassword, new byte[oldPassword.Length]);
                    //List<User> listUser = (from user in _billCollDataContext.Users
                    //                         where user.LoginName == userId && user.Password == oldPassword
                    //                         select user).ToList();

                    var user = _billCollDataContext.Users.Single(u => u.LoginName == userId && u.Password == oldPassword);
                    user.Password = newPassword;
                    _billCollDataContext.SubmitChanges();
                }
            }
            catch (Exception exception)
            {
                throw exception;
            }
        }