public static ActivateUserResponseModel ActivateUserAPI(ActivateUserRequestModel requestApp)
 {
     try
     {
         return(ActivateUser.ActivateUserMethod(requestApp));
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Esempio n. 2
0
        internal static ActivateUserResponseModel ActivateUserMethod(ActivateUserRequestModel requestApp)
        {
            ActivateUserResponseModel responseModel = new ActivateUserResponseModel();
            ErrorResponseModel        errResp       = new ErrorResponseModel();
            RequestException          httpEx        = new RequestException();

            try
            {
                var client  = new RestClient("https://wds.zethconapptest.com/activateuser");
                var request = new RestRequest(Method.POST);
                request.AddHeader("cache-control", "no-cache");
                request.AddHeader("Content-Type", "application/json");
                request.AddParameter("undefined", JObject.FromObject(requestApp), ParameterType.RequestBody);
                IRestResponse response = client.Execute(request);

                switch (response.StatusCode)
                {
                case System.Net.HttpStatusCode.OK:
                    //convert response to object
                    responseModel = Newtonsoft.Json.JsonConvert.DeserializeObject <ActivateUserResponseModel>(response.Content);
                    break;

                case System.Net.HttpStatusCode.BadRequest:
                    //convert error to object
                    errResp = Newtonsoft.Json.JsonConvert.DeserializeObject <ErrorResponseModel>(response.Content);
                    //throw custom exception
                    httpEx = new RequestException(errResp.error.message);
                    httpEx.Data.Add("HttpStatusCode", response.StatusCode);
                    httpEx.Data.Add("ErrorType", errResp.error.type);
                    throw httpEx;

                case System.Net.HttpStatusCode.Unauthorized:
                    //convert error to object
                    errResp = Newtonsoft.Json.JsonConvert.DeserializeObject <ErrorResponseModel>(response.Content);
                    //throw custom exception
                    httpEx = new RequestException(errResp.error.message);
                    httpEx.Data.Add("HttpStatusCode", response.StatusCode);
                    httpEx.Data.Add("ErrorType", errResp.error.type);
                    throw httpEx;

                case System.Net.HttpStatusCode.InternalServerError:
                    //convert error to object
                    errResp = Newtonsoft.Json.JsonConvert.DeserializeObject <ErrorResponseModel>(response.Content);
                    //throw custom exception
                    httpEx = new RequestException(errResp.error.message);
                    httpEx.Data.Add("HttpStatusCode", response.StatusCode);
                    httpEx.Data.Add("ErrorType", errResp.error.type);
                    throw httpEx;

                default:
                    //throw custom exception
                    httpEx.Data.Add("HttpStatusCode", response.StatusCode);
                    throw httpEx;
                }
            }
            catch (RequestException ex)
            {
                throw ex;
            }

            return(responseModel);
        }