示例#1
0
        public User Login(string username, string password)
        {
            var session    = NHibernateSessionManager.GetLocalSession();
            var macAddress = _clientAdapter.GetCurrentClientMacAddress();
            var user       = _userRepository.LoginActiveUser(username, password);
            var terminal   = _terminalRepository.FindByMac(macAddress);

            if (user.IsNull())
            {
                throw new ApplicationException(@"User not found");
            }

            if (terminal == null)
            {
                session.DoTransactional(sess =>
                                        terminal = _terminalRepository.Insert(
                                            new Terminal(
                                                string.Format(@"T-{0}/{1:00}", user.Employee.Branch.Code, _terminalRepository.Count() + 1),
                                                macAddress,
                                                user.Employee.Branch
                                                )
                                            )
                                        );
            }

            LoggedInUser       = user;
            LoggedInUserBranch = user.Employee.Branch;
            LoggedInTerminal   = terminal;

            return(user);
        }