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 IsValidUser(ref string userId, ref string userName, ref bool isActive, ref bool isAdmin, ref int userTypeId, ref string branchCode, ref string branchName, string loginName, string password) { try { _billCollDataContext = new BillCollDataContext(); User user = new User(); password = encryptionDecriptionManager.ComputeHash(password, new byte[password.Length]); isAdmin = false; if (_connectionString.Equals(String.Empty)) { return(false); } else { var reqUser = _billCollDataContext.Users.Single(u => u.LoginName == loginName && u.Password == password); //var reqUser = from user in _billCollDataContext.Users // join branch in _billCollDataContext.BranchLists on user.BranchCode equals branch.branch_code // where user.LoginName == loginName && user.Password == password // select new // { // user,branch.branch_name // }; if (reqUser != null) { userId = "" + reqUser.UserId; userName = reqUser.UserName; isAdmin = reqUser.isAdmin; isActive = reqUser.isActive; userTypeId = reqUser.UserTypeId; branchCode = reqUser.BranchCode; branchName = reqUser.BranchList.branch_name; return(true); } //foreach (var v in reqUser) // { // userId = v.user.UserId; // userName = v.user..UserName; // isAdmin = v.user..isAdmin; // isActive = v.user..isActive; // userTypeId = v.user..UserTypeId; // branchCode = v.user.BranchCode; // branchName = v.branch_name; // return true; // } } } catch (Exception exception) { throw exception; } return(false); }
public List <UserType> GetUserTypeList() { try { _billCollDataContext = new BillCollDataContext(); return(_billCollDataContext.UserTypes.OrderBy(ut => ut.UserTypeId).ToList()); } catch { return(null); } }
public List <BranchList> GetBranchList() { try { _billCollDataContext = new BillCollDataContext(); return(_billCollDataContext.BranchLists.OrderBy(b => b.branch_name).ToList()); } catch (Exception exception) { throw exception; } return(null); }
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(); } }
public bool IsActiveUser(string userId, string password) { try { _billCollDataContext = new BillCollDataContext(); if (_connectionString.Equals(String.Empty)) { return(false); } else { var user = _billCollDataContext.Users.Single(u => u.LoginName == userId && u.Password == password); return(user.isActive); } } catch { return(false); } }
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; } }
public List <User> GetUserDetails(string userId, string branchCode, string userType, string machingCriteria) { _billCollDataContext = new BillCollDataContext(); List <User> listUser = (from user in _billCollDataContext.Users where ((((userId != "" && userId.ToLower() != "all") && ( (machingCriteria == MtbBillCollection.Global.Definitions.MatchingCriteria.Value.Equal.ToString() && user.LoginName == userId) || (machingCriteria == MtbBillCollection.Global.Definitions.MatchingCriteria.Value.EndsWith.ToString() && user.LoginName.StartsWith(userId)) || (machingCriteria == MtbBillCollection.Global.Definitions.MatchingCriteria.Value.StartsWith.ToString() && user.LoginName.EndsWith(userId)) || (machingCriteria == MtbBillCollection.Global.Definitions.MatchingCriteria.Value.Equal.ToString() && user.LoginName.Contains(userId)) ) ) || (userId == "" || userId.ToLower() == "all") ) && ((branchCode.ToLower() != "all" && user.BranchCode == branchCode) || (branchCode.ToLower() == "all")) && ((userType.ToLower() != "all" && user.UserType.TypeName == userType) || (userType.ToLower() == "all")) ) select user).ToList(); return(listUser); //string searchCriteria=" where "; //if (userId != "" && userId.ToLower() != "all") //{ // if(machingCriteria==MtbBillCollection.Global.Definitions.MatchingCriteria.Value.Equal.ToString()) // { // searchCriteria +=" LoginName ='"+userId+"'"; // } // else if (machingCriteria == MtbBillCollection.Global.Definitions.MatchingCriteria.Value.EndsWith.ToString()) // { // searchCriteria +=" LoginName Like '%"+userId+"'"; // } // else if (machingCriteria == MtbBillCollection.Global.Definitions.MatchingCriteria.Value.StartsWith.ToString()) // { // searchCriteria += " LoginName Like '" + userId + "%'"; // } // else if (machingCriteria == MtbBillCollection.Global.Definitions.MatchingCriteria.Value.Contains.ToString()) // { // searchCriteria += " LoginName Like '%" + userId + "%'"; // } //} //if(branchCode.ToLower() != "all") //{ // if(searchCriteria.Trim().ToLower()!="where") // searchCriteria += " AND BranchCode ='" + branchCode + "'"; // else // searchCriteria += " BranchCode ='" + branchCode + "'"; //} //if(userType.ToLower() != "all") //{ // if(searchCriteria.Trim().ToLower()!="where") // searchCriteria += " AND u.UserTypeId =" + userType; // else // searchCriteria += " u.UserTypeId =" + userType; //} //try //{ // _databaseManager = new MssqlDatabaseManager(); // _databaseManager.SetConnectionString = _connectionString; // _databaseManager.OpenDatabaseConnection(); // string sqlQuery = "SELECT UserId,LoginName,UserName,UserDetails,BranchCode,ut.UserType "; // sqlQuery +=" ,(case when isActive=1 Then 'Active' else 'InActive' end) as Active "; // sqlQuery += " FROM Users u INNER JOIN UserType ut on u.UserTypeId=ut.UserTypeId "; // sqlQuery += (searchCriteria.Trim().ToLower()!="where")?searchCriteria:""; // return _databaseManager.GetDataTable(sqlQuery); //} //catch //{ // return null; //} //finally //{ // _databaseManager.CloseDatabaseConnection(); //} }