private static void login(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.login(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 logging user")); } } else { if (callback != null) { callback(null, new NetmeraException(NetmeraException.ErrorCode.EC_USER_LOGIN_ERROR, "Error occurred while logging user")); } } }); }
private static JObject login(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.login(item); } catch (NetmeraException) { throw new NetmeraException(NetmeraException.ErrorCode.EC_USER_LOGIN_ERROR, "Error occurred while logging 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_LOGIN_ERROR, error); } else { throw new NetmeraException(NetmeraException.ErrorCode.EC_USER_LOGIN_ERROR, "Error occurred while logging user"); } } return(json); }