/// <summary>
        /// Function get the Form 941 Return to Efile
        /// </summary>
        /// <param name="submissionId">SubmissionId passed to get the 941 return</param>
        /// <returns>Form941GetReturnResponse</returns>
        public ActionResult GetForm941(Guid submissionId)
        {
            var getReturnResponse     = new Form941GetReturnResponse();
            var getReturnResponseJSON = string.Empty;

            if (submissionId != null && submissionId != Guid.Empty)
            {
                string authType = Utility.GetAppSettings("AuthenticationType");
                if (!string.IsNullOrWhiteSpace(authType) && authType.ToUpper() == "JWT")
                {
                    //Get URLs from App.Config
                    string oAuthApiUrl = Utility.GetAppSettings("OAuthApiUrl");
                    string apiUrl      = Utility.GetAppSettings("PublicAPIUrlWithJWT");

                    //Call OAuth API
                    using (var oAuthClient = new HttpClient())
                    {
                        string oAuthRequestUri = Utility.GetAppSettings("OAuthApiMethodRoute");
                        oAuthClient.BaseAddress = new Uri(oAuthApiUrl);

                        //Generate JWS and get access token (JWT)
                        OAuthGenerator.GenerateJWSAndGetAccessToken(oAuthClient);

                        //Read OAuth API response
                        var response = oAuthClient.GetAsync(oAuthRequestUri).Result;
                        if (response != null && response.IsSuccessStatusCode)
                        {
                            var oauthApiResponse = response.Content.ReadAsAsync <AccessTokenResponse>().Result;
                            if (oauthApiResponse != null && oauthApiResponse.StatusCode == 200)
                            {
                                //Get Access token from OAuth API response
                                string accessToken = oauthApiResponse.AccessToken;
                                //Access token is valid for one hour. After that call OAuth API again & get new Access token.

                                if (!string.IsNullOrWhiteSpace(accessToken))
                                {
                                    //Call TaxBandits API using the Access token
                                    //Access token is valid for one hour. After that call OAuth API again & get new Access token.
                                    using (var apiClient = new HttpClient())
                                    {
                                        //API URL to Get Form 941 Return
                                        string requestUri = "Form941/Get?submissionId=" + submissionId;

                                        apiClient.BaseAddress = new Uri(apiUrl);
                                        //Construct HTTP headers
                                        //If Access token got expired, call OAuth API again & get new Access token.
                                        OAuthGenerator.ConstructHeadersWithAccessToken(apiClient, accessToken);

                                        //Get Response
                                        var _response = apiClient.GetAsync(requestUri).Result;
                                        if (_response != null && _response.IsSuccessStatusCode)
                                        {
                                            //Read Response
                                            var createResponse = _response.Content.ReadAsAsync <Form941GetReturnResponse>().Result;
                                            if (createResponse != null)
                                            {
                                                getReturnResponseJSON = JsonConvert.SerializeObject(createResponse, Formatting.Indented);
                                                getReturnResponse     = new JavaScriptSerializer().Deserialize <Form941GetReturnResponse>(getReturnResponseJSON);
                                                if (getReturnResponse != null && getReturnResponse.StatusCode == (int)StatusCode.Success)
                                                {
                                                    ViewData["GetResponseJSON"] = getReturnResponseJSON;
                                                    return(PartialView());
                                                }
                                            }
                                        }
                                        else
                                        {
                                            var createResponse = _response.Content.ReadAsAsync <Object>().Result;
                                            getReturnResponseJSON = JsonConvert.SerializeObject(createResponse, Formatting.Indented);
                                            getReturnResponse     = new JavaScriptSerializer().Deserialize <Form941GetReturnResponse>(getReturnResponseJSON);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                else
                {
                    using (var client = new PublicAPIClient())
                    {
                        //API URL to Get Form 941 Return
                        string requestUri = "Form941/Get?submissionId=" + submissionId;

                        //Get
                        APIGenerateAuthHeader.GenerateAuthHeader(client, requestUri, "GET");

                        //Get Response
                        var _response = client.GetAsync(requestUri).Result;
                        if (_response != null && _response.IsSuccessStatusCode)
                        {
                            //Read Response
                            var createResponse = _response.Content.ReadAsAsync <Form941GetReturnResponse>().Result;
                            if (createResponse != null)
                            {
                                getReturnResponseJSON = JsonConvert.SerializeObject(createResponse, Formatting.Indented);
                                getReturnResponse     = new JavaScriptSerializer().Deserialize <Form941GetReturnResponse>(getReturnResponseJSON);
                                if (getReturnResponse != null && getReturnResponse.StatusCode == (int)StatusCode.Success)
                                {
                                    ViewData["GetResponseJSON"] = getReturnResponseJSON;
                                    return(PartialView());
                                }
                            }
                        }
                        else
                        {
                            var createResponse = _response.Content.ReadAsAsync <Object>().Result;
                            getReturnResponseJSON = JsonConvert.SerializeObject(createResponse, Formatting.Indented);
                            getReturnResponse     = new JavaScriptSerializer().Deserialize <Form941GetReturnResponse>(getReturnResponseJSON);
                        }
                    }
                }
            }
            return(PartialView(getReturnResponse));
        }
        /// <summary>
        /// Function delete the Form 941 Return to Efile
        /// </summary>
        /// <param name="submissionId">SubmissionId passed to delete the 941 return</param>
        /// <returns>DeleteReturnResponse</returns>
        public ActionResult Delete(Guid submissionId)
        {
            var deleteReturnRequest      = new DeleteReturnRequest();
            var deleteReturnResponse     = new DeleteReturnResponse();
            var deleteReturnResponseJSON = string.Empty;

            if (submissionId != null && submissionId != Guid.Empty)
            {
                deleteReturnRequest.SubmissionId = submissionId;
                // Getting the RecordIds for SubmissionId
                var recordIdsFromSession = APISession.GetForm941RecordIdsBySubmissionId(submissionId);
                deleteReturnRequest.RecordIds = recordIdsFromSession != null ? recordIdsFromSession.RecordIds : null;
                if (deleteReturnRequest.RecordIds != null && deleteReturnRequest.RecordIds.Count > 0)
                {
                    string authType = Utility.GetAppSettings("AuthenticationType");
                    if (!string.IsNullOrWhiteSpace(authType) && authType.ToUpper() == "JWT")
                    {
                        //Get URLs from App.Config
                        string oAuthApiUrl = Utility.GetAppSettings("OAuthApiUrl");
                        string apiUrl      = Utility.GetAppSettings("PublicAPIUrlWithJWT");

                        //Call OAuth API
                        using (var oAuthClient = new HttpClient())
                        {
                            string oAuthRequestUri = Utility.GetAppSettings("OAuthApiMethodRoute");
                            oAuthClient.BaseAddress = new Uri(oAuthApiUrl);

                            //Generate JWS and get access token (JWT)
                            OAuthGenerator.GenerateJWSAndGetAccessToken(oAuthClient);

                            //Read OAuth API response
                            var response = oAuthClient.GetAsync(oAuthRequestUri).Result;
                            if (response != null && response.IsSuccessStatusCode)
                            {
                                var oauthApiResponse = response.Content.ReadAsAsync <AccessTokenResponse>().Result;
                                if (oauthApiResponse != null && oauthApiResponse.StatusCode == 200)
                                {
                                    //Get Access token from OAuth API response
                                    string accessToken = oauthApiResponse.AccessToken;
                                    //Access token is valid for one hour. After that call OAuth API again & get new Access token.

                                    if (!string.IsNullOrWhiteSpace(accessToken))
                                    {
                                        //Call TaxBandits API using the Access token
                                        //Access token is valid for one hour. After that call OAuth API again & get new Access token.
                                        using (var apiClient = new HttpClient())
                                        {
                                            //API URL to Transmit Form 941 Return
                                            string requestUri = "Form941/Delete";

                                            apiClient.BaseAddress = new Uri(apiUrl);
                                            //Construct HTTP headers
                                            //If Access token got expired, call OAuth API again & get new Access token.
                                            OAuthGenerator.ConstructHeadersWithAccessToken(apiClient, accessToken);

                                            //Get Response
                                            var _response = apiClient.PostAsJsonAsync(requestUri, deleteReturnRequest).Result;
                                            if (_response != null && _response.IsSuccessStatusCode)
                                            {
                                                //Read Response
                                                var createResponse = _response.Content.ReadAsAsync <DeleteReturnResponse>().Result;
                                                if (createResponse != null)
                                                {
                                                    deleteReturnResponseJSON = JsonConvert.SerializeObject(createResponse, Formatting.Indented);
                                                    deleteReturnResponse     = new JavaScriptSerializer().Deserialize <DeleteReturnResponse>(deleteReturnResponseJSON);
                                                    if (deleteReturnResponse != null && deleteReturnResponse.StatusCode == (int)StatusCode.Success)
                                                    {
                                                        //Remove Submission and RecordId from session
                                                        APISession.DeleteForm941APIResponse(submissionId);
                                                    }
                                                }
                                            }
                                            else
                                            {
                                                var createResponse = _response.Content.ReadAsAsync <Object>().Result;
                                                deleteReturnResponseJSON = JsonConvert.SerializeObject(createResponse, Formatting.Indented);
                                                deleteReturnResponse     = new JavaScriptSerializer().Deserialize <DeleteReturnResponse>(deleteReturnResponseJSON);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        using (var client = new PublicAPIClient())
                        {
                            //API URL to Transmit Form 941 Return
                            string requestUri = "Form941/Delete";

                            //POST
                            APIGenerateAuthHeader.GenerateAuthHeader(client, requestUri, "POST");

                            //Get Response
                            var _response = client.PostAsJsonAsync(requestUri, deleteReturnRequest).Result;
                            if (_response != null && _response.IsSuccessStatusCode)
                            {
                                //Read Response
                                var createResponse = _response.Content.ReadAsAsync <DeleteReturnResponse>().Result;
                                if (createResponse != null)
                                {
                                    deleteReturnResponseJSON = JsonConvert.SerializeObject(createResponse, Formatting.Indented);
                                    deleteReturnResponse     = new JavaScriptSerializer().Deserialize <DeleteReturnResponse>(deleteReturnResponseJSON);
                                    if (deleteReturnResponse != null && deleteReturnResponse.StatusCode == (int)StatusCode.Success)
                                    {
                                        //Remove Submission and RecordId from session
                                        APISession.DeleteForm941APIResponse(submissionId);
                                    }
                                }
                            }
                            else
                            {
                                var createResponse = _response.Content.ReadAsAsync <Object>().Result;
                                deleteReturnResponseJSON = JsonConvert.SerializeObject(createResponse, Formatting.Indented);
                                deleteReturnResponse     = new JavaScriptSerializer().Deserialize <DeleteReturnResponse>(deleteReturnResponseJSON);
                            }
                        }
                    }
                }
            }
            return(PartialView(deleteReturnResponse));
        }
        public ActionResult APIResponseStatus(Form941Data form941)
        {
            //Hardcoded values for Sequence
            var responseJson = string.Empty;

            form941.Sequence = "Record1";
            form941.RecordId = null;
            form941.ReturnHeader.ReturnType         = null;
            form941.ReturnHeader.Business.IsEIN     = true;
            form941.ReturnHeader.Business.IsForeign = false;

            if (form941?.ReturnHeader?.ThirdPartyDesignee != null && (!string.IsNullOrEmpty(form941.ReturnHeader.ThirdPartyDesignee.Name) || !string.IsNullOrEmpty(form941.ReturnHeader.ThirdPartyDesignee.Phone) || !string.IsNullOrEmpty(form941.ReturnHeader.ThirdPartyDesignee.PIN)))
            {
                form941.ReturnHeader.IsThirdPartyDesignee = true;
            }

            if (form941?.ReturnHeader?.BusinessStatusDetails != null)
            {
                if (form941.ReturnHeader.BusinessStatusDetails.IsBusinessClosed == false)
                {
                    form941.ReturnHeader.BusinessStatusDetails.BusinessClosedDetails = new BusinessClosedDetails();
                }
                if (form941.ReturnHeader.BusinessStatusDetails.IsBusinessTransferred == false)
                {
                    form941.ReturnHeader.BusinessStatusDetails.BusinessTransferredDetails = new BusinessTransferredDetails();
                }
            }

            var form941Response   = new Form941CreateReturnResponse();
            var form941ReturnList = new Form941CreateReturnRequest {
                Form941Records = new List <Form941Data>()
            };

            form941ReturnList.Form941Records.Add(form941);

            // Generate JSON for Form 941
            var    requestJson = JsonConvert.SerializeObject(form941ReturnList, Formatting.Indented);
            string authType    = Utility.GetAppSettings("AuthenticationType");

            if (!string.IsNullOrWhiteSpace(authType) && authType.ToUpper() == "JWT")
            {
                //Get URLs from App.Config
                string oAuthApiUrl = Utility.GetAppSettings("OAuthApiUrl");
                string apiUrl      = Utility.GetAppSettings("PublicAPIUrlWithJWT");

                //Call OAuth API
                using (var oAuthClient = new HttpClient())
                {
                    string oAuthRequestUri = Utility.GetAppSettings("OAuthApiMethodRoute");
                    oAuthClient.BaseAddress = new Uri(oAuthApiUrl);

                    //Generate JWS and get access token (JWT)
                    OAuthGenerator.GenerateJWSAndGetAccessToken(oAuthClient);

                    //Read OAuth API response
                    var response = oAuthClient.GetAsync(oAuthRequestUri).Result;
                    if (response != null && response.IsSuccessStatusCode)
                    {
                        var oauthApiResponse = response.Content.ReadAsAsync <AccessTokenResponse>().Result;
                        if (oauthApiResponse != null && oauthApiResponse.StatusCode == 200)
                        {
                            //Get Access token from OAuth API response
                            string accessToken = oauthApiResponse.AccessToken;
                            //Access token is valid for one hour. After that call OAuth API again & get new Access token.

                            if (!string.IsNullOrWhiteSpace(accessToken))
                            {
                                //Call TaxBandits API using the Access token
                                //Access token is valid for one hour. After that call OAuth API again & get new Access token.
                                using (var apiClient = new HttpClient())
                                {
                                    //API URL to Create Form 941 Return
                                    string requestUri = "Form941/Create";

                                    apiClient.BaseAddress = new Uri(apiUrl);

                                    //Construct HTTP headers
                                    //If Access token got expired, call OAuth API again & get new Access token.
                                    OAuthGenerator.ConstructHeadersWithAccessToken(apiClient, accessToken);

                                    //Get Response
                                    var apiResponse = apiClient.PostAsJsonAsync(requestUri, form941ReturnList).Result;
                                    if (apiResponse != null && response.IsSuccessStatusCode)
                                    {
                                        //Read Response
                                        var createResponse = apiResponse.Content.ReadAsAsync <Form941CreateReturnResponse>().Result;
                                        if (createResponse != null)
                                        {
                                            responseJson = JsonConvert.SerializeObject(createResponse, Formatting.Indented);
                                            //Deserializing JSON (Success Response) to Form941CreateReturnResponse object
                                            form941Response = new JavaScriptSerializer().Deserialize <Form941CreateReturnResponse>(responseJson);
                                            if (form941Response.SubmissionId != null && form941Response.SubmissionId != Guid.Empty)
                                            {
                                                //Adding Form941CreateReturnResponse Response to Session
                                                APISession.AddForm941APIResponse(form941Response);
                                            }
                                        }
                                    }
                                    else
                                    {
                                        var createResponse = apiResponse.Content.ReadAsAsync <Object>().Result;
                                        responseJson = JsonConvert.SerializeObject(createResponse, Formatting.Indented);

                                        //Deserializing JSON (Error Response) to Form941CreateReturnResponse object
                                        form941Response = new JavaScriptSerializer().Deserialize <Form941CreateReturnResponse>(responseJson);
                                    }
                                }
                            }
                        }
                    }
                }
            }
            else
            {
                using (var client = new PublicAPIClient())
                {
                    //API URL to Create Form 941 Return
                    string requestUri = "Form941/Create";

                    //POST
                    APIGenerateAuthHeader.GenerateAuthHeader(client, requestUri, HttpMethod.Post.ToString());

                    //Get Response
                    var response = client.PostAsJsonAsync(requestUri, form941ReturnList).Result;
                    if (response != null && response.IsSuccessStatusCode)
                    {
                        //Read Response
                        var createResponse = response.Content.ReadAsAsync <Form941CreateReturnResponse>().Result;
                        if (createResponse != null)
                        {
                            responseJson = JsonConvert.SerializeObject(createResponse, Formatting.Indented);
                            //Deserializing JSON (Success Response) to Form941CreateReturnResponse object
                            form941Response = new JavaScriptSerializer().Deserialize <Form941CreateReturnResponse>(responseJson);
                            if (form941Response.SubmissionId != null && form941Response.SubmissionId != Guid.Empty)
                            {
                                //Adding Form941CreateReturnResponse Response to Session
                                APISession.AddForm941APIResponse(form941Response);
                            }
                        }
                    }
                    else
                    {
                        var createResponse = response.Content.ReadAsAsync <Object>().Result;
                        responseJson = JsonConvert.SerializeObject(createResponse, Formatting.Indented);

                        //Deserializing JSON (Error Response) to Form941CreateReturnResponse object
                        form941Response = new JavaScriptSerializer().Deserialize <Form941CreateReturnResponse>(responseJson);
                    }
                }
            }

            return(PartialView(form941Response));
        }