// Populate the page with entity data private void PopulatePage() { int batchId = 0; try { // Get object from BatchApi batchId = Int32.Parse(Security.GetQueryString()); BatchDto batch = BatchService.GetBatch(batchId); BatchReferenceTb.Text = batch.Batch_Ref; } catch { // ERROR - User contained invalid data Response.Redirect("BatchDetail?Id{" + batchId + "}&message=DatabaseError"); } List <BatteryDto> batteries = BatteryService.GetBatteries(batchId); if (batteries.Count > 0) { // If there are batteries in this batch; display the gridview BatteryGridView.DataSource = batteries; BatteryGridView.DataBind(); } else { // Otherwise hide the gridview and display an alternative message hiddenDiv.Visible = true; SubtitleDiv.Visible = false; DownloadDiv.Visible = false; } }
// Update this User in the database protected void UpdateBtn_Click(object sender, EventArgs e) { // Create Batch Object int batchId = Int32.Parse(Security.GetQueryString()); BatchDto batch = BatchService.GetBatch(batchId); batch.Batch_Ref = BatchReferenceTb.Text; // Add to database if (BatchService.UpdateBatch(batch)) { Response.Redirect("BatchDetail.aspx?id=" + batchId + "&message=BatchUpdateSuccess"); } else { Response.Redirect("BatchDetail.aspx?id=" + batchId + "&message=UpdateError"); } }