Beispiel #1
0
        public async Task <ResponseJSON> ReadAsync(string id)
        {
            ResponseJSON response = new ResponseJSON();

            try
            {
                if (!string.IsNullOrWhiteSpace(id))
                {
                    var guids = await _testContext.Guid
                                .Where(p => p.UniqueId == id)
                                .ToListAsync();

                    foreach (var item in guids)
                    {
                        response.expire = item.Expires;
                        response.guid   = item.UniqueId;
                        response.user   = item.User;
                    }
                }
            }
            catch (Exception ex)
            {
                response.status = ex.Message;
            }
            return(response);
        }
Beispiel #2
0
 private void SetInfo()
 {
     if (ResponseJSON.ContainsKey(APIConstants.INFO))
     {
         Info = new ResponseInfo((JObject)ResponseJSON[APIConstants.INFO]);
     }
 }
Beispiel #3
0
    private IEnumerator GetResponseCo(string url)
    {
        UnityWebRequest www = UnityWebRequest.Get(url);

        yield return(www.SendWebRequest());

        while (!www.isDone)
        {
            Debug.Log("Progress:" + www.downloadProgress);
            yield return(null);
        }

        if (www.isNetworkError || www.isHttpError)
        {
            Debug.LogError("Network error:" + www.error);
        }
        else
        {
            Statics.response = www.downloadHandler.text;
            Debug.Log("Response:" + www.downloadHandler.text);
            ResponseJSON json = JsonUtility.FromJson <ResponseJSON>(Statics.response);
            Statics.responseJSON = json;
            gridManager.ClearList();
            gridManager.PopulateGrid(Statics.responseJSON.Search);
        }
    }
Beispiel #4
0
 protected override void HandleFaultyResponse()
 {
     if ((HttpStatusCode == APIConstants.ResponseCode.NO_CONTENT) || (HttpStatusCode == APIConstants.ResponseCode.NOT_MODIFIED))
     {
         throw new ZCRMException(true, (int)HttpStatusCode.Value, HttpStatusCode.Value.ToString());
     }
     ZCRMLogger.LogError(ResponseJSON[APIConstants.CODE] + " " + ResponseJSON[APIConstants.MESSAGE]);
     throw new ZCRMException(true, (int)HttpStatusCode.Value, ResponseJSON.GetValue(APIConstants.CODE).ToString(), ResponseJSON.GetValue(APIConstants.MESSAGE).ToString(), ResponseJSON);
 }
Beispiel #5
0
 protected override void HandleFaultyResponse()
 {
     if (HttpStatusCode == APIConstants.ResponseCode.NO_CONTENT)
     {
         throw new ZCRMException(APIConstants.INVALID_DATA, APIConstants.INVALID_ID_MSG);
     }
     ZCRMLogger.LogError(ResponseJSON[APIConstants.CODE] + " " + ResponseJSON[APIConstants.MESSAGE]);
     throw new ZCRMException(ResponseJSON.GetValue(APIConstants.CODE).ToString(), ResponseJSON.GetValue(APIConstants.MESSAGE).ToString());
 }
Beispiel #6
0
        public async Task <IActionResult> Get(string id)
        {
            ResponseJSON res = await _data.ReadAsync(id);

            if (!string.IsNullOrWhiteSpace(res.status))
            {
                return(RedirectToAction("Error", "HandleError"));
            }
            return(Ok(new ApiOkResponse(res)));
        }
Beispiel #7
0
        public async Task <bool> LoginAsync(string id, string password)
        {
            //var keyValues = new List<KeyValuePair<string, string>>
            //{
            //    new KeyValuePair<string, string>("id", userName),
            //    new KeyValuePair<string, string>("pass", password),

            //};

            //var request = new HttpRequestMessage(
            //    HttpMethod.Post, Constants.API_URL);

            //request.Content = new FormUrlEncodedContent(keyValues);

            //var client = new HttpClient();
            //var response = await client.SendAsync(request);
            //var content = await response.Content.ReadAsStringAsync();

            //Debug.WriteLine(content);

            try
            {
                LoginViewModel login_data = new LoginViewModel()
                {
                    id       = id,
                    password = password
                };

                string txt     = this.serialize(login_data);
                var    content = new StringContent(txt, Encoding.UTF8, "application/json");

                HttpClient client = new HttpClient();
                var        resp   = await client.PostAsync(Constants.API_URL + "/user/login", content);

                if (resp.StatusCode == System.Net.HttpStatusCode.OK)
                {
                    string cont = await resp.Content.ReadAsStringAsync();

                    ResponseJSON res_json = (ResponseJSON)this.deserialize(cont, new ResponseJSON());

                    if (res_json.result_code == 100)
                    {
                        Glo.Data.id    = id;
                        Glo.Data.token = res_json.new_token;

                        return(true);
                    }
                }
            }
            catch (Exception e)
            {
                //throw new Exception(e.ToString());
            }
            return(false);
        }
Beispiel #8
0
        public async Task <bool> ProfileUpdateAsync(
            string email,
            string password,
            string name,
            string mobile)
        {
            try
            {
                RegistartionViewModel register = new RegistartionViewModel()
                {
                    email    = email,
                    password = password,
                    name     = name,
                    mobile   = mobile
                };

                string txt = this.serialize(register);

                var content = new StringContent(txt, Encoding.UTF8, "application/json");

                HttpClient client = new HttpClient();
                client.DefaultRequestHeaders.Add("Authorization", "Bearer " + Glo.Data.token);
                var resp = await client.PostAsync(Constants.API_URL + "/user/register", content);

                if (resp.StatusCode == HttpStatusCode.OK)
                {
                    //var cont= resp.Content.ReadAsStringAsync().ToString();

                    string cont = await resp.Content.ReadAsStringAsync();

                    //await DisplayAlert("Result", cont, "OK");
                    //cont = await resp.Content.ReadAsStringAsync().Result;

                    ResponseJSON res_json = (ResponseJSON)this.deserialize(cont, new ResponseJSON());

                    if (res_json.result_code == 100)
                    {
                        //await DisplayAlert("Result", cont, "OK");
                        return(true);
                    }

                    //Helpers.Utils.Msgbox(cont);

                    //await DisplayAlert("Hey", "Your record has been added", "Alright");
                }
            }
            catch (Exception e)
            {
                //throw new Exception(e.ToString());
            }

            return(false);
        }
Beispiel #9
0
        protected override void HandleFaultyResponse()
        {
            string code = null, message = null;

            if ((HttpStatusCode == APIConstants.ResponseCode.NO_CONTENT) || (HttpStatusCode == APIConstants.ResponseCode.NOT_MODIFIED))
            {
                throw new ZCRMException(true, (int)HttpStatusCode.Value, HttpStatusCode.Value.ToString());
            }
            code    = ResponseJSON.ContainsKey(APIConstants.CODE) ? ResponseJSON[APIConstants.CODE].ToString() : "ERROR";
            message = ResponseJSON.ContainsKey(APIConstants.MESSAGE) ? ResponseJSON[APIConstants.MESSAGE].ToString() : "Empty response";
            ZCRMLogger.LogError(code + " " + message);
            throw new ZCRMException(true, (int)HttpStatusCode.Value, code, message, ResponseJSON);
        }
    public static ResponseJSON GetResponse(NineDigital nineDigital)
    {
        ResponseJSON Res             = null;
        int          responseArrayNo = 0;

        for (int i = 0; i < nineDigital.Payload.Length; i++)
        {
            if (nineDigital.Payload[i].DRM == true && nineDigital.Payload[i].EpisodeCount > 0)
            {
                responseArrayNo++;
            }
        }
        return(Res);
    }
Beispiel #11
0
        protected override void ProcessDataResponse()
        {
            JObject msgJSON = ResponseJSON;

            if (msgJSON.ContainsKey(APIConstants.DATA))
            {
                JArray recordsArray = (JArray)ResponseJSON.GetValue(APIConstants.DATA);
                msgJSON = (JObject)recordsArray[0];
            }
            if (msgJSON.ContainsKey(APIConstants.TAGS))
            {
                JArray tagsArray = (JArray)ResponseJSON.GetValue(APIConstants.TAGS);
                msgJSON = (JObject)tagsArray[0];
            }
            if (msgJSON.ContainsKey(APIConstants.USERS))
            {
                JArray usersArray = (JArray)ResponseJSON.GetValue(APIConstants.USERS);
                msgJSON = (JObject)usersArray[0];
            }
            if (msgJSON.ContainsKey(APIConstants.MESSAGE))
            {
                Message = msgJSON.GetValue(APIConstants.MESSAGE).ToString();
            }

            if (msgJSON.ContainsKey(APIConstants.STATUS))
            {
                Status = msgJSON.GetValue(APIConstants.STATUS).ToString();
                if (Status.Equals(APIConstants.CODE_ERROR))
                {
                    if (msgJSON.ContainsKey(APIConstants.DETAILS))
                    {
                        //TODO: Inspect the working of this part;
                        throw new ZCRMException(msgJSON.GetValue(APIConstants.CODE).ToString(), Message, msgJSON.GetValue(APIConstants.DETAILS) as JObject);
                    }
                    throw new ZCRMException(msgJSON.GetValue(APIConstants.CODE).ToString(), Message);
                }
            }
            //NOTE: For the user photo download method.
            else if (msgJSON.ContainsKey("status_code"))
            {
                Status = msgJSON["status_code"].ToString();
                if (msgJSON.ContainsKey("errors"))
                {
                    JArray errorDetails = (JArray)msgJSON["errors"];
                    throw new ZCRMException("Status_code :" + (string)msgJSON["status_code"] + ", Error details: " + errorDetails[0]["code"] + ", Resource :" + errorDetails[0]["resource"]);
                }
                throw new ZCRMException("Status_code :" + (string)msgJSON["status_code"] + msgJSON.ToString());
            }
        }
Beispiel #12
0
        protected override void ProcessDataResponse()
        {
            BulkEntitiesResponse = new List <EntityResponse>();
            JArray recordsArray = new JArray();

            if (ResponseJSON.ContainsKey(APIConstants.DATA))
            {
                recordsArray = (JArray)ResponseJSON[APIConstants.DATA];
                foreach (JObject recordJSON in recordsArray)
                {
                    if (recordJSON.ContainsKey(APIConstants.STATUS))
                    {
                        EntityResponse individualResponse = new EntityResponse(recordJSON);
                        BulkEntitiesResponse.Add(individualResponse);
                    }
                }
            }
            else if (ResponseJSON.ContainsKey(APIConstants.TAGS))
            {
                recordsArray = (JArray)ResponseJSON[APIConstants.TAGS];
                foreach (JObject recordJSON in recordsArray)
                {
                    if (recordJSON.ContainsKey(APIConstants.STATUS))
                    {
                        EntityResponse individualResponse = new EntityResponse(recordJSON);
                        BulkEntitiesResponse.Add(individualResponse);
                    }
                }
            }
            else if (ResponseJSON.ContainsKey(APIConstants.TAXES))
            {
                recordsArray = (JArray)ResponseJSON[APIConstants.TAXES];
                foreach (JObject recordJSON in recordsArray)
                {
                    if (recordJSON.ContainsKey(APIConstants.STATUS))
                    {
                        EntityResponse individualResponse = new EntityResponse(recordJSON);
                        BulkEntitiesResponse.Add(individualResponse);
                    }
                }
            }
        }
Beispiel #13
0
        private string ProcessResponse(Dictionary <string, string> res)
        {
            string result;

            if (res["statuscode"] == "OK")
            {
                ResponseJSON successUserResponse = JSON.Deserialize <ResponseJSON>(res["response"]);
                if (!string.IsNullOrWhiteSpace(successUserResponse.result.guid))
                {
                    result = "Guid sucessfully created " + successUserResponse.result.guid + " and expires in " + successUserResponse.result.expire;
                }
                else
                {
                    result = "Guid not found";
                }
            }
            else if (res["statuscode"] == "InternalServerError")
            {
                result = "There seems to be a server error. Please try again later";
            }
            else if (res["statuscode"] == "BadRequest")
            {
                BadRequestResponse badRequestResponse = JSON.Deserialize <BadRequestResponse>(res["response"]);
                StringBuilder      stringBuilder      = new StringBuilder();
                foreach (var item in badRequestResponse.errors)
                {
                    stringBuilder.Append(item + Environment.NewLine);
                }

                result = stringBuilder.ToString();
            }
            else
            {
                result = "Route Not Found";
            }

            return(result);
        }
Beispiel #14
0
        [HttpPost("{id?}")] // id is an optional parameter
        public async Task <IActionResult> Post([FromBody] RequestJSON requestJSON)
        {
            string expire = string.Empty;
            string guid   = string.Empty;

            if (RouteData.Values["id"] != null)
            {
                guid = RouteData.Values["id"].ToString();
            }
            else
            {
                guid = _utils.ComputeGuid();
            }
            if (!string.IsNullOrWhiteSpace(requestJSON.expire))
            {
                expire = requestJSON.expire;
            }
            else
            {
                expire = _utils.ComputeExpirationTime();
            }
            RequestJSON request = new RequestJSON
            {
                expire = expire,
                user   = requestJSON.user,
                guid   = guid
            };

            ResponseJSON res = await _data.CreateUpdateAsync(request);

            if (!string.IsNullOrWhiteSpace(res.status))
            {
                return(RedirectToAction("Error", "HandleError"));
            }
            return(Ok(new ApiOkResponse(res)));
        }
Beispiel #15
0
        public async Task <bool> SignupAsync(
            string email,
            string password,
            string name,
            string mobile)
        {
            try
            {
                RegistartionViewModel register = new RegistartionViewModel()
                {
                    email    = email,
                    password = password,
                    name     = name,
                    mobile   = mobile
                };

                string txt = this.serialize(register);

                //var xml = this.tiny_serialize(register);
                //await DisplayAlert("Result", xml, "OK");
                //Helpers.Utils.Msgbox(xml);

                //var aaa = await content.ReadAsStringAsync();
                //await DisplayAlert("Request", json, "OK");

                var content = new StringContent(txt, Encoding.UTF8, "application/json");
                //txt = await content.ReadAsStringAsync();

                HttpClient client = new HttpClient();
                var        resp   = await client.PostAsync(Constants.API_URL + "/user/register", content);

                //var resp = await client.GetAsync(Constants.API_URL+"/user/register");

                //System.Console.WriteLine("@Signupbtn: content="+content);
                //Helpers.Utils.Msgbox(""+result.StatusCode);

                if (resp.StatusCode == HttpStatusCode.OK)
                {
                    //var cont= resp.Content.ReadAsStringAsync().ToString();

                    string cont = await resp.Content.ReadAsStringAsync();

                    //await DisplayAlert("Result", cont, "OK");
                    //cont = await resp.Content.ReadAsStringAsync().Result;

                    ResponseJSON res_json = (ResponseJSON)this.deserialize(cont, new ResponseJSON());

                    if (res_json.result_code == 100)
                    {
                        //await DisplayAlert("Result", cont, "OK");
                        return(true);
                    }

                    //Helpers.Utils.Msgbox(cont);

                    //await DisplayAlert("Hey", "Your record has been added", "Alright");
                }
            }
            catch (Exception e)
            {
                //throw new Exception(e.ToString());
            }

            return(false);
        }
Beispiel #16
0
        protected override void ProcessDataResponse()
        {
            JObject msgJSON = ResponseJSON;

            if (msgJSON.ContainsKey(APIConstants.DATA))
            {
                JArray recordsArray = (JArray)ResponseJSON.GetValue(APIConstants.DATA);
                msgJSON = (JObject)recordsArray[0];
            }
            if (msgJSON.ContainsKey(APIConstants.TAGS))
            {
                JArray tagsArray = (JArray)ResponseJSON.GetValue(APIConstants.TAGS);
                msgJSON = (JObject)tagsArray[0];
            }
            if (msgJSON.ContainsKey(APIConstants.USERS))
            {
                JArray usersArray = (JArray)ResponseJSON.GetValue(APIConstants.USERS);
                msgJSON = (JObject)usersArray[0];
            }
            if (msgJSON.ContainsKey(APIConstants.MESSAGE))
            {
                Message = msgJSON.GetValue(APIConstants.MESSAGE).ToString();
            }

            if (msgJSON.ContainsKey(APIConstants.STATUS))
            {
                Status = msgJSON.GetValue(APIConstants.STATUS).ToString();
                if (Status.Equals(APIConstants.CODE_ERROR))
                {
                    if (msgJSON.ContainsKey(APIConstants.DETAILS))
                    {
                        //TODO: Inspect the working of this part;
                        throw new ZCRMException(true, (int)HttpStatusCode.Value, msgJSON.GetValue(APIConstants.CODE).ToString(), Message, msgJSON.GetValue(APIConstants.DETAILS) as JObject);
                    }
                    throw new ZCRMException(true, (int)HttpStatusCode.Value, msgJSON.GetValue(APIConstants.CODE).ToString(), Message);
                }
            }
            //NOTE: For the user photo download method.
            else if (msgJSON.ContainsKey("status_code"))
            {
                Status = msgJSON["status_code"].ToString();
                if (msgJSON.ContainsKey("errors"))
                {
                    JArray errorDetails = (JArray)msgJSON["errors"];
                    throw new ZCRMException(true, (int)HttpStatusCode.Value, HttpStatusCode.Value.ToString(), "Status_code :" + (string)msgJSON["status_code"] + ", Error details: " + errorDetails[0]["code"] + ", Resource :" + errorDetails[0]["resource"]);
                }
                throw new ZCRMException(true, (int)HttpStatusCode.Value, HttpStatusCode.Value.ToString(), "Status_code :" + (string)msgJSON["status_code"] + msgJSON.ToString());
            }
            //NOTE : while uploading the file if the org id is wrong the below else-if block will handle it.
            else if (msgJSON.ContainsKey("x-error"))
            {
                ZCRMLogger.LogInfo(ToString());
                JToken infoMessageToken = msgJSON.GetValue("info");
                string infoMessage      = null;
                if (infoMessageToken != null && infoMessageToken.Type != JTokenType.Null)
                {
                    infoMessage = infoMessageToken.ToString();
                }
                throw new ZCRMException(true, (int)HttpStatusCode.Value, HttpStatusCode.Value.ToString(), infoMessage, msgJSON);
            }
        }
Beispiel #17
0
        public async Task <ResponseJSON> CreateUpdateAsync(RequestJSON createrequest)
        {
            ResponseJSON response = new ResponseJSON();

            try
            {
                // Get record and update
                var uniqueid = await _testContext.Guid
                               .Where(p => p.UniqueId == createrequest.guid && p.User == createrequest.user)
                               .FirstOrDefaultAsync();

                if (uniqueid != null)
                {
                    if (!string.IsNullOrWhiteSpace(createrequest.expire))
                    {
                        uniqueid.Expires = createrequest.expire;
                    }
                    if (!string.IsNullOrWhiteSpace(createrequest.user))
                    {
                        uniqueid.User = createrequest.user;
                    }
                    await _testContext.SaveChangesAsync();

                    // Query the record back
                    var list = await _testContext.Guid
                               .Where(p => p.UniqueId == createrequest.guid)
                               .ToListAsync();

                    foreach (var item in list)
                    {
                        response.expire = item.Expires;
                        response.guid   = item.UniqueId;
                        response.user   = item.User;
                    }
                }
                else
                {
                    Models.Guid newguid = new Models.Guid
                    {
                        Expires  = createrequest.expire,
                        UniqueId = createrequest.guid,
                        User     = createrequest.user
                    };
                    _testContext.Add(newguid);
                    await _testContext.SaveChangesAsync();

                    var guids = await _testContext.Guid
                                .Where(p => p.UniqueId == createrequest.guid)
                                .ToListAsync();

                    foreach (var item in guids)
                    {
                        response.expire = item.Expires;
                        response.guid   = item.UniqueId;
                        response.user   = item.User;
                    }
                }
            }
            catch (Exception ex)
            {
                response.status = ex.Message;
            }
            return(response);
        }