Esempio n. 1
0
        /// <summary>
        /// Login function
        /// </summary>
        /// <param name="model">Login model</param>
        /// <param name="returnValue">Return value from data 0: Account not found, 1: Success, -1: Account is login, -2, Exception</param>
        /// <returns>UserModel</returns>
        public UserModel Login(LoginModel model, out int returnValue)
        {
            UserModel _return = new UserModel()
            {
            };

            try
            {
                using (var _context = new TDHEntities())
                {
                    string          _password = Utils.Security.PasswordSecurityHelper.GetHashedPassword(model.Password);
                    ObjectParameter _output   = new ObjectParameter("STATUS", typeof(int));
                    var             _md       = _context.PROC_SYS_LOGIN(model.UserName, _password, model.IsMobile, model.PlatForm, model.Version, model.UserAgent, model.HostName, model.HostAddress, model.SessionID, _output).FirstOrDefault();
                    returnValue = (int)_output.Value;
                    if (_md == null)
                    {
                        return(_return);
                    }
                    return(new UserModel()
                    {
                        ID = (Guid)_md.user_id,
                        UserName = _md.user_name,
                        Token = _md.token
                    });
                }
            }
            catch (Exception ex)
            {
                throw new ServiceException(FILE_NAME, MethodInfo.GetCurrentMethod().Name, new Guid(), ex);
            }
        }