/// <summary> /// Adds a TaxCode under the specified realm. The realm must be set in the context. /// </summary> /// <param name="taxCode">TaxCode to Add.</param> public void AddTaxCodeAsync(Intuit.Ipp.Data.TaxService taxCode) { Console.Write("AddAsync started \n"); this.serviceContext.IppConfiguration.Logger.CustomLogger.Log(Diagnostics.TraceLevel.Info, "Called Method Add Asynchronously."); GlobalTaxServiceCallCompletedEventArgs <Intuit.Ipp.Data.TaxService> callCompletedEventArgs = new GlobalTaxServiceCallCompletedEventArgs <Intuit.Ipp.Data.TaxService>(); Console.Write("callCompletedEventArgs instantiated \n"); if (!GlobalTaxServiceHelper.IsTypeNull(taxCode)) { IdsException exception = new IdsException(Resources.ParameterNotNullMessage, new ArgumentNullException(Resources.EntityString)); Console.Write("IdsException instantiated \n"); this.serviceContext.IppConfiguration.Logger.CustomLogger.Log(Diagnostics.TraceLevel.Error, string.Format(CultureInfo.InvariantCulture, Resources.ExceptionGeneratedMessage, exception.ToString())); callCompletedEventArgs.Error = exception; this.OnAddTaxCodeAsyncCompleted(this, callCompletedEventArgs); } else { try { GlobalAsyncTaxService asyncService = new GlobalAsyncTaxService(this.serviceContext); asyncService.OnAddTaxCodeAsyncCompleted += new GlobalTaxServiceCallback <Intuit.Ipp.Data.TaxService> .GlobalTaxServiceCallCompletedEventHandler(this.AddTaxCodeAsyncCompleted); asyncService.AddTaxCodeAsync(taxCode as Intuit.Ipp.Data.TaxService); } catch (SystemException systemException) { this.serviceContext.IppConfiguration.Logger.CustomLogger.Log(TraceLevel.Error, systemException.Message); IdsException idsException = new IdsException(systemException.Message); callCompletedEventArgs.Error = idsException; this.OnAddTaxCodeAsyncCompleted(this, callCompletedEventArgs); } } }
/// <summary> /// Adds a TaxCode under the specified realm. The realm must be set in the context. /// </summary> /// <param name="taxCode">TaxCode to Add.</param> /// <returns>Returns an updated version of the entity with updated identifier.</returns> public Intuit.Ipp.Data.TaxService AddTaxCode(Intuit.Ipp.Data.TaxService taxCode) { this.serviceContext.IppConfiguration.Logger.CustomLogger.Log(Diagnostics.TraceLevel.Info, "Called Method AddTaxCode for TaxService."); // Validate parameter if (!GlobalTaxServiceHelper.IsTypeNull(taxCode)) { IdsException exception = new IdsException(Resources.ParameterNotNullMessage, new ArgumentNullException(Resources.EntityString)); this.serviceContext.IppConfiguration.Logger.CustomLogger.Log(Diagnostics.TraceLevel.Error, string.Format(CultureInfo.InvariantCulture, Resources.ExceptionGeneratedMessage, exception.ToString())); IdsExceptionManager.HandleException(exception); } string resourceString = taxCode.GetType().Name.ToLower(CultureInfo.InvariantCulture); // Builds resource Uri string uri = string.Format(CultureInfo.InvariantCulture, "{0}/company/{1}/{2}/taxcode", CoreConstants.VERSION, this.serviceContext.RealmId, resourceString); // Creates request parameters RequestParameters parameters; if (this.serviceContext.IppConfiguration.Message.Request.SerializationFormat == Intuit.Ipp.Core.Configuration.SerializationFormat.Json) { parameters = new RequestParameters(uri, HttpVerbType.POST, CoreConstants.CONTENTTYPE_APPLICATIONJSON); } else { parameters = new RequestParameters(uri, HttpVerbType.POST, CoreConstants.CONTENTTYPE_APPLICATIONXML); } // Prepares request HttpWebRequest request = this.restHandler.PrepareRequest(parameters, taxCode); string response = string.Empty; try { // gets response response = this.restHandler.GetResponse(request); } catch (IdsException ex) { IdsExceptionManager.HandleException(ex); } CoreHelper.CheckNullResponseAndThrowException(response); // de serialize object IntuitResponse restResponse = (IntuitResponse)CoreHelper.GetSerializer(this.serviceContext, false).Deserialize <IntuitResponse>(response); this.serviceContext.IppConfiguration.Logger.CustomLogger.Log(Diagnostics.TraceLevel.Info, "Finished Executing Method Add."); return((Intuit.Ipp.Data.TaxService)(restResponse.AnyIntuitObject as Intuit.Ipp.Data.TaxService)); }