void btnAddSelectedJob_Click(object sender, EventArgs e) { Facade.ResourceManifest facResourceManifest = new Orchestrator.Facade.ResourceManifest(); int highestJobOrder = 0; // Find the highest job order and simply add it to the end foreach (Entities.ResourceManifestJob rmj in this.SavedResourceManifest.ResourceManifestJobs) { if (rmj.JobOrder > highestJobOrder) { highestJobOrder = rmj.JobOrder; } } foreach (GridItem row in grdResourceManifestAddJobs.Items) { if (row.ItemType == GridItemType.AlternatingItem || row.ItemType == GridItemType.Item) { HtmlInputHidden hidJobId = row.FindControl("hidJobId") as HtmlInputHidden; HtmlInputHidden hidJobOrder = row.FindControl("hidJobOrder") as HtmlInputHidden; CheckBox chkDriverManifest = row.FindControl("chkDriverManifest") as CheckBox; if (chkDriverManifest.Checked) { int jobId = int.Parse(hidJobId.Value); // Double check to make sure the rmj isn't already on the manifest. Entities.ResourceManifestJob rmj = this.SavedResourceManifest.ResourceManifestJobs.Find(o => o.JobId == Convert.ToInt32(hidJobId.Value)); if (rmj != null) { // The rmj is already on the manifest, simply change its removed flag if (rmj.Removed == true) { rmj.Removed = false; } } else { //Get Instructions Resourced Facade.Instruction facInstruction = new Facade.Instruction(); List <int> instructionIDs = facInstruction.GetInstructionIDsForDriverResource(jobId, this.SavedResourceManifest.ResourceId, true); foreach (int instructionID in instructionIDs) { // create a new rmj to add to the manifest Entities.ResourceManifestJob newRmj = new Orchestrator.Entities.ResourceManifestJob(); newRmj.JobOrder = ++highestJobOrder; newRmj.ResourceManifestId = this.SavedResourceManifest.ResourceManifestId; newRmj.JobId = Convert.ToInt32(hidJobId.Value); newRmj.InstructionId = instructionID; this.SavedResourceManifest.ResourceManifestJobs.Add(newRmj); } } } } } facResourceManifest.UpdateResourceManifest(this.SavedResourceManifest, this.Page.User.Identity.Name); this.SavedResourceManifest = facResourceManifest.GetResourceManifest(this.ResourceManifestId); grdResourceManifestJobs.Rebind(); // Clear the add jobs grid. grdResourceManifestAddJobs.DataSource = null; grdResourceManifestAddJobs.DataBind(); pnlAddJobs.Visible = false; pnlExistingManifest.Visible = true; }