Beispiel #1
0
        private bool LogIn()
        {
            using (var ctx = new ChequeDBDataContext())
            {
                UserLog log =
                    ctx.UserLogs
                    .FirstOrDefault(x => x.UserId == _user.Id && x.MachineName == Environment.MachineName && x.LoginTime != null);
                if (log != null)
                {
                    LogOut();
                }
                CheckViewModel.Instance.User = _user;

                log = new UserLog()
                {
                    MachineName = Environment.MachineName,
                    LoginTime   = DateTime.Now,
                    Status      = "LogIn",
                    UserId      = _user.Id,
                };

                ctx.UserLogs.InsertOnSubmit(log);
                //ctx.UserLogs.Add(log);

                ctx.SubmitChanges();
            }
            //  db.Dispose();
            return(true);
        }
Beispiel #2
0
        private bool LogOut()
        {
            if (_user == null)
            {
                return(false);
            }


            using (var ctx = new ChequeDBDataContext())
            {
                UserLog log = ctx.UserLogs.OrderByDescending(x => x.LoginTime).FirstOrDefault(x => x.UserId == _user.Id && x.MachineName == Environment.MachineName);

                if (log != null && log.Status == "LogIn")
                {
                    log.MachineName = Environment.MachineName;
                    log.LogoutTime  = DateTime.Now;
                    log.Status      = "LogOut";
                    log.UserId      = _user.Id;
                    //log.User = user;

                    //ctx.UserLogs.(log);
                    ctx.SubmitChanges();
                }
                //db.Dispose();
                return(true);
            }
        }
Beispiel #3
0
        private bool Authenticate(string user, string pass)
        {
            using (var ctx = new ChequeDBDataContext())
            {
                _user = ctx.Users.FirstOrDefault(x => x.LoginName == user);


                if (_user != null && _user.Password == pass)
                {
                    _user.UserPermissions.Load();
                    return(LogIn());
                }
                else
                {
                    return(false);
                }
            }
        }