public TaxScheduleActionResult <TaxScheduleInsertionResult> InsertTaxScheduleDetails(MunicipalityTaxDetails tax) { logger.Trace("{0} request received with parameters: {1}: {2}", nameof(InsertTaxScheduleDetails), nameof(tax), tax?.DebuggerDisplay); if (tax == null) { throw new ArgumentNullException(nameof(tax)); // argument exceptions are not internal errors, but errors with the caller, so we can throw these } if (tax.MunicipalitySchedule == null) { throw new ArgumentNullException(nameof(tax.MunicipalitySchedule)); } var insertResult = TaxScheduleInsertionResult.InsertionNotAttempted; var checkValidity = TaxScheduleValidationResult.Unknown; try { checkValidity = TaxValidator.ValidateTaxDetails(tax); logger.Trace("{0} validity status is: {1}", nameof(tax), checkValidity); if (checkValidity == TaxScheduleValidationResult.Valid) { try { // NOTE: if multithreaded, there could be a race condition between the existence check and insertion if (TaxStorage.TaxScheduleExists(tax.MunicipalitySchedule)) { insertResult = TaxScheduleInsertionResult.TaxScheduleAlreadyExists; } else { TaxStorage.InsertTaxSchedule(tax); insertResult = TaxScheduleInsertionResult.Success; } } catch (Exception) { insertResult = TaxScheduleInsertionResult.UnknownFailure; throw; // this will be re-caught further down } } } catch (Exception ex) { logger.Error(ex, "Exception occurred in {0} method", nameof(InsertTaxScheduleDetails)); #if DEBUG if (Debugger.IsAttached) { Debugger.Break(); } #endif } var response = new TaxScheduleActionResult <TaxScheduleInsertionResult>(checkValidity, insertResult); logger.Trace("Returning {0} response: {1}", nameof(InsertTaxScheduleDetails), response.ToString()); return(response); }
public TaxScheduleActionResult <TaxScheduleUpdateResult> UpdateTaxScheduleDetails(MunicipalityTaxDetails tax) { logger.Trace("{0} request received with parameters: {1}: {2}", nameof(UpdateTaxScheduleDetails), nameof(tax), tax?.DebuggerDisplay); if (tax == null) { throw new ArgumentNullException(nameof(tax)); } if (tax.MunicipalitySchedule == null) { throw new ArgumentNullException(nameof(tax.MunicipalitySchedule)); } var updateResult = TaxScheduleUpdateResult.UpdateNotAttempted; var checkValidity = TaxScheduleValidationResult.Unknown; try { checkValidity = TaxValidator.ValidateTaxDetails(tax); logger.Trace("{0} validity status is: {1}", nameof(tax), checkValidity); if (checkValidity == TaxScheduleValidationResult.Valid) { try { // NOTE: if multithreaded, there could be a race condition between the existence check and updating, maybe some other thread will delete it meanwhile // - we could use locks or (depending on the provider) a specific transaction type to prevent this if (!TaxStorage.TaxScheduleExists(tax.MunicipalitySchedule)) { updateResult = TaxScheduleUpdateResult.ExistingTaxScheduleNotFound; } else { TaxStorage.UpdateTaxSchedule(tax); updateResult = TaxScheduleUpdateResult.Success; } } catch (Exception) { updateResult = TaxScheduleUpdateResult.UnknownFailure; throw; // this will be re-caught further down } } } catch (Exception ex) { logger.Error(ex, "Exception occurred in {0} method", nameof(UpdateTaxScheduleDetails)); #if DEBUG if (Debugger.IsAttached) { Debugger.Break(); } #endif } var response = new TaxScheduleActionResult <TaxScheduleUpdateResult>(checkValidity, updateResult); logger.Trace("Returning {0} response: {1}", nameof(UpdateTaxScheduleDetails), response.ToString()); return(response); }