/// <param name='operations'> /// Reference to the BoomTax.Api.SampleProject.IForm1094COperations. /// </param> /// <param name='filingId'> /// Required. /// </param> /// <param name='form1094C'> /// Required. /// </param> public static int Post(this IForm1094COperations operations, int filingId, Form1094C form1094C) { return(Task.Factory.StartNew((object s) => { return ((IForm1094COperations)s).PostAsync(filingId, form1094C); } , operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult()); }
/// <param name='operations'> /// Reference to the BoomTax.Api.SampleProject.IForm1094COperations. /// </param> /// <param name='filingId'> /// Required. /// </param> /// <param name='form1094C'> /// Required. /// </param> /// <param name='cancellationToken'> /// Cancellation token. /// </param> public static async Task <int> PostAsync(this IForm1094COperations operations, int filingId, Form1094C form1094C, CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { Microsoft.Rest.HttpOperationResponse <int> result = await operations.PostWithOperationResponseAsync(filingId, form1094C, cancellationToken).ConfigureAwait(false); return(result.Body); }
/// <param name='filingId'> /// Required. /// </param> /// <param name='form1094C'> /// Required. /// </param> /// <param name='cancellationToken'> /// Cancellation token. /// </param> public async Task <HttpOperationResponse <int> > PostWithOperationResponseAsync(int filingId, Form1094C form1094C, CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { // Validate if (form1094C == null) { throw new ArgumentNullException("form1094C"); } // Tracing bool shouldTrace = ServiceClientTracing.IsEnabled; string invocationId = null; if (shouldTrace) { invocationId = ServiceClientTracing.NextInvocationId.ToString(); Dictionary <string, object> tracingParameters = new Dictionary <string, object>(); tracingParameters.Add("filingId", filingId); tracingParameters.Add("form1094C", form1094C); ServiceClientTracing.Enter(invocationId, this, "PostAsync", tracingParameters); } // Construct URL string url = ""; url = url + "/2016/Form1094C"; List <string> queryParameters = new List <string>(); queryParameters.Add("filingId=" + Uri.EscapeDataString(filingId.ToString())); if (queryParameters.Count > 0) { url = url + "?" + string.Join("&", queryParameters); } string baseUrl = this.Client.BaseUri.AbsoluteUri; // Trim '/' character from the end of baseUrl and beginning of url. if (baseUrl[baseUrl.Length - 1] == '/') { baseUrl = baseUrl.Substring(0, baseUrl.Length - 1); } if (url[0] == '/') { url = url.Substring(1); } url = baseUrl + "/" + url; url = url.Replace(" ", "%20"); // Create HTTP transport objects HttpRequestMessage httpRequest = new HttpRequestMessage(); httpRequest.Method = HttpMethod.Post; httpRequest.RequestUri = new Uri(url); // Set Headers // Set Credentials if (this.Client.Credentials != null) { cancellationToken.ThrowIfCancellationRequested(); await this.Client.Credentials.ProcessHttpRequestAsync(httpRequest, cancellationToken).ConfigureAwait(false); } // Serialize Request string requestContent = null; JToken requestDoc = form1094C.SerializeJson(null); requestContent = requestDoc.ToString(Newtonsoft.Json.Formatting.Indented); httpRequest.Content = new StringContent(requestContent, Encoding.UTF8); httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json"); // Send Request if (shouldTrace) { ServiceClientTracing.SendRequest(invocationId, httpRequest); } cancellationToken.ThrowIfCancellationRequested(); HttpResponseMessage httpResponse = await this.Client.HttpClient.SendAsync(httpRequest, cancellationToken).ConfigureAwait(false); if (shouldTrace) { ServiceClientTracing.ReceiveResponse(invocationId, httpResponse); } HttpStatusCode statusCode = httpResponse.StatusCode; cancellationToken.ThrowIfCancellationRequested(); string responseContent = await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); if (statusCode != HttpStatusCode.OK) { HttpOperationException <object> ex = new HttpOperationException <object>(); ex.Request = httpRequest; ex.Response = httpResponse; ex.Body = null; if (shouldTrace) { ServiceClientTracing.Error(invocationId, ex); } throw ex; } // Create Result HttpOperationResponse <int> result = new HttpOperationResponse <int>(); result.Request = httpRequest; result.Response = httpResponse; // Deserialize Response if (statusCode == HttpStatusCode.OK) { int resultModel = default(int); JToken responseDoc = null; if (string.IsNullOrEmpty(responseContent) == false) { responseDoc = JToken.Parse(responseContent); } if (responseDoc != null) { resultModel = ((int)responseDoc); } result.Body = resultModel; } if (shouldTrace) { ServiceClientTracing.Exit(invocationId, result); } return(result); }
/// <param name='id'> /// Required. /// </param> /// <param name='cancellationToken'> /// Cancellation token. /// </param> public async Task <HttpOperationResponse <Form1094C> > GetWithOperationResponseAsync(int id, CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { // Tracing bool shouldTrace = ServiceClientTracing.IsEnabled; string invocationId = null; if (shouldTrace) { invocationId = ServiceClientTracing.NextInvocationId.ToString(); Dictionary <string, object> tracingParameters = new Dictionary <string, object>(); tracingParameters.Add("id", id); ServiceClientTracing.Enter(invocationId, this, "GetAsync", tracingParameters); } // Construct URL string url = ""; url = url + "/2016/Form1094C/"; url = url + Uri.EscapeDataString(id.ToString()); string baseUrl = this.Client.BaseUri.AbsoluteUri; // Trim '/' character from the end of baseUrl and beginning of url. if (baseUrl[baseUrl.Length - 1] == '/') { baseUrl = baseUrl.Substring(0, baseUrl.Length - 1); } if (url[0] == '/') { url = url.Substring(1); } url = baseUrl + "/" + url; url = url.Replace(" ", "%20"); // Create HTTP transport objects HttpRequestMessage httpRequest = new HttpRequestMessage(); httpRequest.Method = HttpMethod.Get; httpRequest.RequestUri = new Uri(url); // Set Credentials if (this.Client.Credentials != null) { cancellationToken.ThrowIfCancellationRequested(); await this.Client.Credentials.ProcessHttpRequestAsync(httpRequest, cancellationToken).ConfigureAwait(false); } // Send Request if (shouldTrace) { ServiceClientTracing.SendRequest(invocationId, httpRequest); } cancellationToken.ThrowIfCancellationRequested(); HttpResponseMessage httpResponse = await this.Client.HttpClient.SendAsync(httpRequest, cancellationToken).ConfigureAwait(false); if (shouldTrace) { ServiceClientTracing.ReceiveResponse(invocationId, httpResponse); } HttpStatusCode statusCode = httpResponse.StatusCode; cancellationToken.ThrowIfCancellationRequested(); string responseContent = await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); if (statusCode != HttpStatusCode.OK) { HttpOperationException <object> ex = new HttpOperationException <object>(); ex.Request = httpRequest; ex.Response = httpResponse; ex.Body = null; if (shouldTrace) { ServiceClientTracing.Error(invocationId, ex); } throw ex; } // Create Result HttpOperationResponse <Form1094C> result = new HttpOperationResponse <Form1094C>(); result.Request = httpRequest; result.Response = httpResponse; // Deserialize Response if (statusCode == HttpStatusCode.OK) { Form1094C resultModel = new Form1094C(); JToken responseDoc = null; if (string.IsNullOrEmpty(responseContent) == false) { responseDoc = JToken.Parse(responseContent); } if (responseDoc != null) { resultModel.DeserializeJson(responseDoc); } result.Body = resultModel; } if (shouldTrace) { ServiceClientTracing.Exit(invocationId, result); } return(result); }
private static async Task Start() { string baseUrl = ConfigurationManager.AppSettings["BaseUrl"]; HttpResponseMessage response = new HttpResponseMessage(); using (var loginClient = new HttpClient { BaseAddress = new Uri(baseUrl) }) { //login and get token var credentials = new FormUrlEncodedContent(new Dictionary <string, string> { { "username", ConfigurationManager.AppSettings["UserName"] }, { "password", ConfigurationManager.AppSettings["Password"] }, { "grant_type", "password" } }); response = await loginClient.PostAsync("Token", credentials); } if (response.IsSuccessStatusCode) { //parse token string loginResult = await response.Content.ReadAsStringAsync(); dynamic data = JToken.Parse(loginResult); var token = data.access_token.ToString(); using (BoomTaxApi client = new BoomTaxApi(new Uri(baseUrl), new TokenCredentials(token))) { Console.WriteLine($"Getting filing types"); var filingTypes = await client.FilingType.GetFilingTypesAsync(); var aca2016FilingType = filingTypes.FirstOrDefault(o => o.TaxYear == 2016 && o.Name == "ACA Reporting (1094C/1095C)"); Console.WriteLine($"Creating filing..."); var filing = client.Filing.Post(aca2016FilingType.Id.Value, "ABC Corporation"); Console.WriteLine($"Filing id: {filing.Id}"); //all examples from pre-January 2016 test scenario #region header form data var headerFormData = new Form1094C() { CompanyName = "Darrtestfive", Ein = "000000599", Address = "4689 Redwood Avenue", City = "Austin", State = "TX", Zip = "78755", CountryCode = "US", ContactFirstName = "Susan", ContactLastName = "Williamson", ContactPhone = "5551234567", TotalNumberOfForms = "322", IsAuthoritativeTransmittal = true, IsQualifyingOfferMethod = true, IsSection4980HTransitionRelief = true, IsMinimumOfferYesJan = true, IsMinimumOfferYesFeb = true, IsMinimumOfferYesMar = true, IsMinimumOfferYesApr = true, IsMinimumOfferYesMay = true, IsMinimumOfferYesJun = true, IsMinimumOfferYesJul = true, IsMinimumOfferYesAug = true, IsMinimumOfferYesSep = true, IsMinimumOfferYesOct = true, IsMinimumOfferYesNov = true, IsMinimumOfferYesDec = true, IsAggregatedGroupJan = true, IsAggregatedGroupFeb = true, IsAggregatedGroupMar = true, IsAggregatedGroupApr = true, IsAggregatedGroupMay = true, IsAggregatedGroupJun = true, IsAggregatedGroupJul = true, IsAggregatedGroupAug = true, IsAggregatedGroupSep = true, IsAggregatedGroupOct = true, IsAggregatedGroupNov = true, IsAggregatedGroupDec = true, IsSection4980hAll12MonthsSpecified = true, Section4980HTransitionReliefIndicatorAll12Months = "A", FullTimeEmployeeCountJan = 315, TotalEmployeeCountJan = 330, FullTimeEmployeeCountFeb = 316, TotalEmployeeCountFeb = 335, FullTimeEmployeeCountMar = 316, TotalEmployeeCountMar = 335, FullTimeEmployeeCountApr = 316, TotalEmployeeCountApr = 335, FullTimeEmployeeCountMay = 316, TotalEmployeeCountMay = 335, FullTimeEmployeeCountJun = 316, TotalEmployeeCountJun = 335, FullTimeEmployeeCountJul = 318, TotalEmployeeCountJul = 335, FullTimeEmployeeCountAug = 318, TotalEmployeeCountAug = 333, FullTimeEmployeeCountSep = 318, TotalEmployeeCountSep = 333, FullTimeEmployeeCountOct = 318, TotalEmployeeCountOct = 333, FullTimeEmployeeCountNov = 318, TotalEmployeeCountNov = 333, FullTimeEmployeeCountDec = 318, TotalEmployeeCountDec = 333, IsMemberOfAggregateAle = true, Ein1 = "000000600", Name1 = "Darrtestfive Subsidiary One" }; #endregion Console.WriteLine($"Adding header form..."); var headerFormId = client.Form1094C.Post(filing.Id.Value, headerFormData); Console.WriteLine($"Header form id: {headerFormId}"); //populate our 1095-Cs //this is using static data from test scenarios. //you will likely want to pull this from your database var form1095Cs = Get1095CData(); int lastFormId = 0; //add 1095-Cs foreach (var form in form1095Cs) { Console.WriteLine($"Adding form for employee: {form.FirstName} {form.LastName}"); lastFormId = client.Form1095C.Post(filing.Id.Value, form); Console.WriteLine($"Created form with id: {lastFormId}"); } //update a form (we changed the SSN in this case) //make sure to include all fields, not just the updated fields. #region updated form data var updatedForm = new Form1095C { FirstName = "Odette", MiddleName = "Cloudy", LastName = "Davidson", Address = "2993 Spruce Lane", City = "Fort Collins", State = "CO", Zip = "80522", CountryCode = "US", EmployerPhone = "5551234545", PlanStartMonth = "01", Ssn = "000000534", OfferOfCoverageAll12Months = "1A", //EmployeeShareAll12Months = 0, CoveredIndividuals = new List <CoveredIndividual>() { new CoveredIndividual() { FirstName = "Peter", MiddleName = "", LastName = "Davidson", Dob = new DateTime(1970, 2, 6), All12Months = true }, new CoveredIndividual() { FirstName = "Mindy", LastName = "Davidson", Ssn = "000000534", All12Months = true }, new CoveredIndividual() { FirstName = "Nicolas", MiddleName = "", LastName = "Davidson", Ssn = "000000535", All12Months = true }, } }; #endregion Console.WriteLine($"Updating form at id: {lastFormId}"); client.Form1095C.Put(lastFormId, updatedForm); Console.WriteLine($"Deleting form at id: {lastFormId}"); client.Form1095C.Delete(lastFormId); Console.WriteLine($"Form deleted."); Console.WriteLine($"Initiating e-file request..."); //initiate e-file and add emails for notifications. //note: This could generate more than 1 efile request depending on what has changed since the previous e-file. IList <int> efileRequestIds = new List <int>(); //e-filing will not be available until late December/early January. //until then, this will throw an error. try { efileRequestIds = client.EfileRequest.Post(filing.Id.Value, "*****@*****.**", isSilent: false); } catch (HttpOperationException ex) { Console.WriteLine(ex.Response.AsFormattedString()); } //***************************************************************************************** //DO NOT POLL A GIVEN ID MORE THAN ONCE EVERY 15 MINUTES OR YOUR ACCOUNT MAY BE RESTRICTED. //***************************************************************************************** if (efileRequestIds.Any()) { Console.WriteLine($"Checking e-file request..."); var efileRequest = client.EfileRequest.GetEfileRequest(efileRequestIds.First()); //if the e-file request is complete, this means we have a response from the IRS. if (efileRequest.IsComplete ?? false) { Console.WriteLine($"E-File request complete. Getting response."); var efileResponse = client.EfileResponse.Get(efileRequest.EfileResponseId.Value); //get receipt and receipt detail Console.WriteLine($"ReceiptId: {efileResponse.ReceiptId}, ReceivedOn: {efileResponse.ReceivedOn}, Status: {efileResponse.Status}"); //get form errors foreach (var errorDetails in efileResponse.Errors) { Console.WriteLine($"FormId:{errorDetails.FormId}, ErrorCode:{errorDetails.ErrorCode}, ErrorMessage:{errorDetails.ErrorMessage}"); } } } Console.WriteLine($"Deleting filing..."); client.Filing.Delete(filing.Id.Value); Console.WriteLine($"Filing deleted."); } Console.ReadKey(); } }