public UsersWM FindUser(Expression <Func <Users, bool> > predicate)
 {
     try
     {
         return(UsersMapping.MapToWM(_usersOperations.FindUser(predicate)));
     }
     catch (Exception ex)
     {
         throw new Exception(ex.ToString());
     }
 }
Esempio n. 2
0
        public void PublishToken(string userName, string password, int expiryTime, int notBeforeTime)
        {
            try
            {
                if (string.IsNullOrEmpty(userName))
                {
                    throw new Exception(ErrorMessageConstants.UserNameNotFound);
                }

                if (string.IsNullOrEmpty(password))
                {
                    throw new Exception(ErrorMessageConstants.UserPasswordNotFound);
                }

                var user = _userOperations.FindUser(x => x.UserAppName == userName && x.UserPassword == password);

                if (user == null)
                {
                    throw new Exception(ErrorMessageConstants.UserNotFound);
                }

                string token = _userTokensOperations.PublishToken(userName, password, expiryTime, notBeforeTime);

                UserTokensWM userToken = new UserTokensWM
                {
                    UserID       = user.FirstOrDefault().UserID,
                    UserToken    = token,
                    CreationDate = DateTime.Now,
                    ExpiryDate   = DateTime.Now.AddMinutes(expiryTime)
                };

                AddUserToken(userToken);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.ToString());
            }
        }