Exemplo n.º 1
0
        private void accountUpdate(RequestItem item, Action <JObject, Exception> callback)
        {
            if (String.IsNullOrEmpty(item.getEmail()))
            {
                if (callback != null)
                {
                    callback(null, new NetmeraException(NetmeraException.ErrorCode.EC_REQUIRED_FIELD, NetmeraConstants.Netmera_UserEmail + " is required"));
                }
            }
            if (String.IsNullOrEmpty(item.getPassword()))
            {
                if (callback != null)
                {
                    callback(null, new NetmeraException(NetmeraException.ErrorCode.EC_REQUIRED_FIELD, NetmeraConstants.Netmera_UserPassword + " is required"));
                }
            }

            NetmeraHttpUtils.accountUpdate(item, (json, ex) =>
            {
                if (json != null)
                {
                    if (json["data"] != null && json["data"].First != null)
                    {
                        if (callback != null)
                        {
                            callback((JObject)json.First.First, ex);
                        }
                    }
                    else if (json["error"] != null)
                    {
                        String error = json["error"]["message"].ToString();
                        if (callback != null)
                        {
                            callback(null, new NetmeraException(NetmeraException.ErrorCode.EC_USER_UPDATE_ERROR, error));
                        }
                    }
                    else
                    if (callback != null)
                    {
                        callback(null, new NetmeraException(NetmeraException.ErrorCode.EC_USER_UPDATE_ERROR, "Error occurred while updating user"));
                    }
                }
                else
                {
                    if (callback != null)
                    {
                        callback(null, new NetmeraException(NetmeraException.ErrorCode.EC_USER_UPDATE_ERROR, "Error occurred while updating user"));
                    }
                }
            });
        }
Exemplo n.º 2
0
        private JObject accountUpdate(RequestItem item)
        {
            JObject json = null;

            if (String.IsNullOrEmpty(item.getEmail()))
            {
                throw new NetmeraException(NetmeraException.ErrorCode.EC_REQUIRED_FIELD, NetmeraConstants.Netmera_UserEmail + " is required");
            }
            if (String.IsNullOrEmpty(item.getPassword()))
            {
                throw new NetmeraException(NetmeraException.ErrorCode.EC_REQUIRED_FIELD, NetmeraConstants.Netmera_UserPassword + " is required");
            }
            try
            {
                json = NetmeraHttpUtils.accountUpdate(item);
            }
            catch (NetmeraException)
            {
                throw new NetmeraException(NetmeraException.ErrorCode.EC_USER_UPDATE_ERROR, "Error occurred while updating user");
            }
            if (json != null)
            {
                if (json["data"] != null && json["data"].Count() != 0)
                {
                    return((JObject)json.First.First);
                }
                else if (json["error"] != null)
                {
                    String error = json["error"]["message"].ToString();
                    throw new NetmeraException(NetmeraException.ErrorCode.EC_USER_UPDATE_ERROR, error);
                }
                else
                {
                    throw new NetmeraException(NetmeraException.ErrorCode.EC_USER_UPDATE_ERROR, "Error occurred while updating user");
                }
            }
            return(null);
        }