/// <summary>
        ///  Get Form941 RecordIDs by SubmissionId
        /// </summary>
        /// <param name="submissionId"></param>
        /// <returns></returns>
        public TransmitForm GetForm941RecordIdsBySubmissionId(Guid submissionId)
        {
            TransmitForm transmitForm = new TransmitForm();
            List <Form941ReturnResponse> returnResponses = Form941ReturnResponses;

            if (submissionId != Guid.Empty)
            {
                transmitForm.SubmissionId = submissionId;
                if (returnResponses != null && returnResponses.Count > 0)
                {
                    var returnResponse = returnResponses.Where(r => r.SubmissionId == submissionId).SingleOrDefault();
                    if (returnResponse != null && returnResponse.Form941Records != null &&
                        returnResponse.Form941Records.SuccessRecords != null && returnResponse.Form941Records.SuccessRecords.Count > 0)
                    {
                        var recordIds = returnResponse.Form941Records.SuccessRecords.Select(r => r.RecordId).ToList();
                        if (recordIds != null && recordIds.Any())
                        {
                            transmitForm.RecordIds = new List <Guid>();
                            foreach (var recordId in recordIds)
                            {
                                transmitForm.RecordIds.Add(recordId ?? Guid.Empty);
                            }
                        }
                    }
                }
            }
            return(transmitForm);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Function transmit the Form W-2 Return to Efile
        /// </summary>
        /// <param name="submissionId">SubmissionId passed to transmit the W-2 return</param>
        /// <returns>TransmitFormW2Response</returns>
        public ActionResult _TransmitReturn(Guid submissionId)
        {
            TransmitForm           transmitFormW2         = new TransmitForm();
            TransmitFormW2Response transmitFormW2Response = new TransmitFormW2Response();
            var transmitFormW2ResponseJSON = string.Empty;

            if (submissionId != null && submissionId != Guid.Empty)
            {
                // Getting the RecordIds for SubmissionId
                transmitFormW2 = APISession.GetRecordIdsBySubmissionId(submissionId);

                // Generate JSON for TransmitFormW2
                var requestJson = JsonConvert.SerializeObject(transmitFormW2, Formatting.Indented);

                if (transmitFormW2 != null)
                {
                    using (var client = new PublicAPIClient())
                    {
                        //API URL to Transmit Form W-2 Return
                        string requestUri = "FormW2/Transmit";

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

                        //Get Response
                        var _response = client.PostAsJsonAsync(requestUri, transmitFormW2).Result;
                        if (_response != null && _response.IsSuccessStatusCode)
                        {
                            //Read Response
                            var createResponse = _response.Content.ReadAsAsync <TransmitFormW2Response>().Result;
                            if (createResponse != null)
                            {
                                transmitFormW2ResponseJSON = JsonConvert.SerializeObject(createResponse, Formatting.Indented);
                                transmitFormW2Response     = new JavaScriptSerializer().Deserialize <TransmitFormW2Response>(transmitFormW2ResponseJSON);
                                if (transmitFormW2Response.SubmissionId != null && transmitFormW2Response.SubmissionId != Guid.Empty && transmitFormW2Response.StatusCode == (int)StatusCode.Success)
                                {
                                    //Updating Filing Status (Transmitted) for a specific SubmissionId in Session
                                    APISession.UpdateFilingStatus(transmitFormW2Response.SubmissionId);
                                }
                            }
                        }
                        else
                        {
                            var createResponse = _response.Content.ReadAsAsync <Object>().Result;
                            transmitFormW2ResponseJSON = JsonConvert.SerializeObject(createResponse, Formatting.Indented);
                            transmitFormW2Response     = new JavaScriptSerializer().Deserialize <TransmitFormW2Response>(transmitFormW2ResponseJSON);
                        }
                    }
                }
            }
            return(PartialView(transmitFormW2Response));
        }
Exemplo n.º 3
0
        /// <summary>
        /// Function transmit the Form 941 Return to Efile
        /// </summary>
        /// <param name="submissionId">SubmissionId passed to transmit the 941 return</param>
        /// <returns>TransmitFormW2Response</returns>
        public ActionResult _TransmitReturn(Guid submissionId)
        {
            TransmitForm transmitForm941             = new TransmitForm();
            var          transmitForm941Response     = new TransmitForm941Response();
            var          transmitForm941ResponseJSON = string.Empty;

            if (submissionId != null && submissionId != Guid.Empty)
            {
                transmitForm941.SubmissionId = submissionId;
                // Generate JSON for TransmitForm 941
                var requestJson = JsonConvert.SerializeObject(transmitForm941, Formatting.Indented);
                if (transmitForm941 != null)
                {
                    //Get URLs from App.Config
                    string ApiUrl = Utility.GetAppSettings(Constants.PublicAPIUrlWithJWT);
                    //Get Access token from GetAccessToken Class
                    GetAccessToken AccessToken          = new GetAccessToken(HttpContext);
                    var            GeneratedAccessToken = AccessToken.GetGeneratedAccessToken();
                    if (!string.IsNullOrWhiteSpace(GeneratedAccessToken))
                    {
                        using (var apiClient = new HttpClient())
                        {
                            //API URL to Transmit Form 941 Return
                            string requestUri = "Form941/Transmit";

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

                            //Get Response
                            var _response = apiClient.PostAsJsonAsync(requestUri, transmitForm941).Result;
                            if (_response != null && _response.IsSuccessStatusCode)
                            {
                                //Read Response
                                var createResponse = _response.Content.ReadAsAsync <TransmitForm941Response>().Result;
                                if (createResponse != null)
                                {
                                    transmitForm941ResponseJSON = JsonConvert.SerializeObject(createResponse, Formatting.Indented);
                                    transmitForm941Response     = new JavaScriptSerializer().Deserialize <TransmitForm941Response>(transmitForm941ResponseJSON);
                                    if (transmitForm941Response.SubmissionId != null && transmitForm941Response.SubmissionId != Guid.Empty && transmitForm941Response.StatusCode == (int)StatusCodeList.Success)
                                    {
                                        //Updating Filing Status (Transmitted) for a specific SubmissionId in Session
                                        //bool Isupdated = APISession.UpdateForm941ReturnFilingStatus(transmitForm941Response.SubmissionId);
                                        //if (Isupdated)
                                        //{
                                        //    transmitForm941Response.IsReturnTransmitted = true;
                                        //}
                                    }
                                }
                            }
                            else
                            {
                                var createResponse = _response.Content.ReadAsAsync <Object>().Result;
                                transmitForm941ResponseJSON = JsonConvert.SerializeObject(createResponse, Formatting.Indented);
                                transmitForm941Response     = new JavaScriptSerializer().Deserialize <TransmitForm941Response>(transmitForm941ResponseJSON);
                            }
                        }
                    }
                }
            }
            return(PartialView(transmitForm941Response));
        }
        /// <summary>
        /// Function transmit the Form 941 Return to Efile
        /// </summary>
        /// <param name="submissionId">SubmissionId passed to transmit the 941 return</param>
        /// <returns>TransmitFormW2Response</returns>
        public ActionResult _TransmitReturn(Guid submissionId)
        {
            var transmitForm941             = new TransmitForm();
            var transmitForm941Response     = new TransmitForm941Response();
            var transmitForm941ResponseJSON = string.Empty;

            if (submissionId != null && submissionId != Guid.Empty)
            {
                // Getting the RecordIds for SubmissionId
                transmitForm941 = APISession.GetForm941RecordIdsBySubmissionId(submissionId);

                // Generate JSON for TransmitForm 941
                var requestJson = JsonConvert.SerializeObject(transmitForm941, Formatting.Indented);

                if (transmitForm941 != null)
                {
                    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/Transmit";

                                            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, transmitForm941).Result;
                                            if (_response != null && _response.IsSuccessStatusCode)
                                            {
                                                //Read Response
                                                var createResponse = _response.Content.ReadAsAsync <TransmitForm941Response>().Result;
                                                if (createResponse != null)
                                                {
                                                    transmitForm941ResponseJSON = JsonConvert.SerializeObject(createResponse, Formatting.Indented);
                                                    transmitForm941Response     = new JavaScriptSerializer().Deserialize <TransmitForm941Response>(transmitForm941ResponseJSON);
                                                    if (transmitForm941Response.SubmissionId != null && transmitForm941Response.SubmissionId != Guid.Empty && transmitForm941Response.StatusCode == (int)StatusCode.Success)
                                                    {
                                                        //Updating Filing Status (Transmitted) for a specific SubmissionId in Session
                                                        APISession.UpdateForm941ReturnFilingStatus(transmitForm941Response.SubmissionId);
                                                    }
                                                }
                                            }
                                            else
                                            {
                                                var createResponse = _response.Content.ReadAsAsync <Object>().Result;
                                                transmitForm941ResponseJSON = JsonConvert.SerializeObject(createResponse, Formatting.Indented);
                                                transmitForm941Response     = new JavaScriptSerializer().Deserialize <TransmitForm941Response>(transmitForm941ResponseJSON);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        using (var client = new PublicAPIClient())
                        {
                            //API URL to Transmit Form 941 Return
                            string requestUri = "Form941/Transmit";

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

                            //Get Response
                            var _response = client.PostAsJsonAsync(requestUri, transmitForm941).Result;
                            if (_response != null && _response.IsSuccessStatusCode)
                            {
                                //Read Response
                                var createResponse = _response.Content.ReadAsAsync <TransmitForm941Response>().Result;
                                if (createResponse != null)
                                {
                                    transmitForm941ResponseJSON = JsonConvert.SerializeObject(createResponse, Formatting.Indented);
                                    transmitForm941Response     = new JavaScriptSerializer().Deserialize <TransmitForm941Response>(transmitForm941ResponseJSON);
                                    if (transmitForm941Response.SubmissionId != null && transmitForm941Response.SubmissionId != Guid.Empty && transmitForm941Response.StatusCode == (int)StatusCode.Success)
                                    {
                                        //Updating Filing Status (Transmitted) for a specific SubmissionId in Session
                                        APISession.UpdateForm941ReturnFilingStatus(transmitForm941Response.SubmissionId);
                                    }
                                }
                            }
                            else
                            {
                                var createResponse = _response.Content.ReadAsAsync <Object>().Result;
                                transmitForm941ResponseJSON = JsonConvert.SerializeObject(createResponse, Formatting.Indented);
                                transmitForm941Response     = new JavaScriptSerializer().Deserialize <TransmitForm941Response>(transmitForm941ResponseJSON);
                            }
                        }
                    }
                }
            }
            return(PartialView(transmitForm941Response));
        }