/// <summary> /// Function inputs Form W-2 details, POST all those details to the API and returns the response. /// Successful response contains SubmissionId, StatusCode and RecordSuccessStatus details (Sequence, RecordId, RecordStatus etc) /// Error response contains StatusCode and RecordErrorStatus details (RecordId, Sequence and list of Error information such as Code, Name, Message and Type) /// </summary> /// <param name="formw2">Form W-2 details passed through formw2 parameter</param> /// <returns>W2CreateReturnResponse</returns> public ActionResult APIResponseStatus(FormW2 formw2) { //Hardcoded values for Sequence and TaxYear var responseJson = string.Empty; formw2.TaxYear = 2017; formw2.Sequence = "Record1"; W2CreateReturnResponse w2response = new W2CreateReturnResponse(); W2CreateReturnRequest w2ReturnList = new W2CreateReturnRequest(); w2ReturnList.W2Forms = new List <FormW2>(); w2ReturnList.W2Forms.Add(formw2); // Generate JSON for Form W-2 var requestJson = JsonConvert.SerializeObject(w2ReturnList, Formatting.Indented); using (var client = new PublicAPIClient()) { //API URL to Create Form W-2 Return string requestUri = "FormW2/Create"; //POST APIGenerateAuthHeader.GenerateAuthHeader(client, requestUri, "POST"); //Get Response var _response = client.PostAsJsonAsync(requestUri, w2ReturnList).Result; if (_response != null && _response.IsSuccessStatusCode) { //Read Response var createResponse = _response.Content.ReadAsAsync <W2CreateReturnResponse>().Result; if (createResponse != null) { responseJson = JsonConvert.SerializeObject(createResponse, Formatting.Indented); //Deserializing JSON (Success Response) to W2CreateReturnResponse object w2response = new JavaScriptSerializer().Deserialize <W2CreateReturnResponse>(responseJson); if (w2response.SubmissionId != null && w2response.SubmissionId != Guid.Empty) { //Adding W2CreateReturnResponse Response to Session APISession.AddAPIResponse(w2response); } } } else { var createResponse = _response.Content.ReadAsAsync <Object>().Result; responseJson = JsonConvert.SerializeObject(createResponse, Formatting.Indented); //Deserializing JSON (Error Response) to W2CreateReturnResponse object w2response = new JavaScriptSerializer().Deserialize <W2CreateReturnResponse>(responseJson); } } return(PartialView(w2response)); }