private void btnSave_Click( object sender, RoutedEventArgs e )
{
try
{
RockConfig rockConfig = RockConfig.Load();
RockRestClient client = new RockRestClient( rockConfig.RockBaseUrl );
client.Login( rockConfig.Username, rockConfig.Password );
FinancialBatch financialBatch = null;
if ( SelectedFinancialBatch == null || SelectedFinancialBatch.Id == 0 )
{
financialBatch = new FinancialBatch { Id = 0, Guid = Guid.NewGuid(), Status = BatchStatus.Pending, CreatedByPersonAliasId = LoggedInPerson.PrimaryAliasId };
}
else
{
financialBatch = client.GetData<FinancialBatch>( string.Format( "api/FinancialBatches/{0}", SelectedFinancialBatch.Id ) );
}
txtBatchName.Text = txtBatchName.Text.Trim();
if ( string.IsNullOrWhiteSpace( txtBatchName.Text ) )
{
txtBatchName.Style = this.FindResource( "textboxStyleError" ) as Style;
return;
}
else
{
txtBatchName.Style = this.FindResource( "textboxStyle" ) as Style;
}
financialBatch.Name = txtBatchName.Text;
Campus selectedCampus = cbCampus.SelectedItem as Campus;
if ( selectedCampus.Id > 0 )
{
financialBatch.CampusId = selectedCampus.Id;
}
else
{
financialBatch.CampusId = null;
}
financialBatch.BatchStartDateTime = dpBatchDate.SelectedDate;
if ( !string.IsNullOrWhiteSpace( txtControlAmount.Text ) )
{
financialBatch.ControlAmount = decimal.Parse( txtControlAmount.Text.Replace( "$", string.Empty ) );
}
else
{
financialBatch.ControlAmount = 0.00M;
}
txtNote.Text = txtNote.Text.Trim();
financialBatch.Note = txtNote.Text;
if ( financialBatch.Id == 0 )
{
client.PostData<FinancialBatch>( "api/FinancialBatches/", financialBatch );
}
else
{
client.PutData<FinancialBatch>( "api/FinancialBatches/", financialBatch, financialBatch.Id );
}
if ( SelectedFinancialBatch == null || SelectedFinancialBatch.Id == 0 )
{
// refetch the batch to get the Id if it was just Inserted
financialBatch = client.GetDataByGuid<FinancialBatch>( "api/FinancialBatches", financialBatch.Guid );
SelectedFinancialBatch = financialBatch;
}
LoadFinancialBatchesGrid();
UpdateBatchUI( financialBatch );
ShowBatch( false );
}
catch ( Exception ex )
{
ShowException( ex );
}
}