private AuthorizationKeyStatusModel GetModel(String type, String name, String authorizationKey, bool createIfNotExists)
        {
            Assert.EmptyString(type, "type");
            Assert.EmptyString(name, "name");
            Assert.EmptyString(authorizationKey, "authorizationKey");
            var qry = _store.CreateQuery <AuthorizationKeyStatusModel>();

            qry.AddFilterEqual("AccountType", type);
            qry.AddFilterEqual("AccountName", name);
            qry.AddFilterEqual("AuthorizationKey", authorizationKey);
            var result = qry.FindFirst();

            if (result == null && createIfNotExists)
            {
                result = new AuthorizationKeyStatusModel()
                {
                    AccountType      = type,
                    AccountName      = name,
                    AuthorizationKey = authorizationKey,
                    Status           = AuthorizationStatus.Default
                };
            }
            return(result);
        }
Example #2
0
        private IUser GetUserInternal(String login, bool throwIfNotExists)
        {
            Assert.EmptyString(login, "login");
            IUser result = null;

            login = login.ToLower();
            if (!_users.TryGetValue(login, out result))
            {
                var qry = _store.CreateQuery <UserModel>();
                qry.AddFilterEqual("Login", login);
                var model = qry.FindFirst();
                if (model != null)
                {
                    result        = new UserImpl(GetSchemaInternal(model.SchemaId, true), model);
                    _users[login] = result;
                }
            }
            if (result == null && throwIfNotExists)
            {
                throw new InvalidOperationException("Não existe um usuário com o login " + throwIfNotExists);
            }

            return(result);
        }