public virtual async Task <IActionResult> DeleteConfirmed(Guid id) { await _businessObject.Delete(id, User.Identity.Name); CreateMessage(Resource.SuccessMessageType, Resource.RemovedSuccessfully); return(RedirectToAction(nameof(Index))); }
private void AddGrid(GridView grid, ImageButton addNewRowButton, string tableName) { Panel panel = new Panel(); panel.CssClass = "PDSectionHolder"; panel.Style["padding"] = "5px"; panel.Style["width"] = "auto"; grid.Style["margin-left"] = "15px"; grid.Style["margin-top"] = "0px"; // add clear items columns GridRowClearImage clearBtnColumn = new GridRowClearImage(); grid.Columns.Add(clearBtnColumn); string[] keyNames = grid.DataKeyNames; // validate: LockedBy bool validateAuditField = lockableTables.Contains(tableName); // add delete button in special cases if (ALLOW_TABLE_DELETES.Contains(tableName)) { string priKeyName = BOL.BusinessObject.GetPrimaryKeyName(tableName); GridRowDeleteImage deleteButton = new GridRowDeleteImage(); grid.Columns.Add(deleteButton); grid.RowDeleting += (o, e) => { GridViewRow gridRow = grid.Rows[e.RowIndex]; HiddenField priKeyField = gridRow.FindControl(priKeyName) as HiddenField; if (priKeyField != null && !string.IsNullOrEmpty(priKeyField.Value)) { // delete record int priKey = int.Parse(priKeyField.Value); BusinessObject bo = BusinessObjectFactory.BuildBusinessObject(tableName); bo.Delete(priKey); // reset patient item fields Dictionary <string, IEnumerable <int> > destTableToKeys = new Dictionary <string, IEnumerable <int> >(); destTableToKeys.Add(tableName, new int[] { priKey }); string username = new Security.SecurityController().GetUserName(); ProtocolMgmtDa.ClearProtocolMgrPatientFieldsWithPKey(PatientItemId, destTableToKeys, username); // TODO: proper redirect Response.Redirect(Request.Url.PathAndQuery, true); } }; } // add hidden keys as input fields (used for UI) var hiddenKeyNames = keyNames.Except(new string[] { Patient.PatientId }); grid.RowCreated += (sender, e) => { int lastCellIndex = e.Row.Cells.Count - 1; if (lastCellIndex > -1) { TableCell lastCell = e.Row.Cells[lastCellIndex]; foreach (string key in hiddenKeyNames) { HiddenField hidden = new HiddenField(); hidden.ID = key; // add field to cell lastCell.Controls.Add(hidden); } } }; // suppress clear button for existing records grid.RowDataBound += (sender, e) => { // data retriever DataRowView dataRow = e.Row.DataItem as DataRowView; Func <string, object> getRowValue = (fieldName) => { return(dataRow != null && dataRow.Row.Table.Columns[fieldName] != null ? dataRow[fieldName] : null); }; if (e.Row.RowType == DataControlRowType.DataRow && e.Row.DataItem != null) { bool hasEmptyKeys = false; // for each key field, set associated hidden field foreach (string key in keyNames) { string keyValue = getRowValue(key) + ""; HiddenField hidden = e.Row.FindControl(key) as HiddenField; if (hidden != null) { hidden.Value = keyValue; } hasEmptyKeys = hasEmptyKeys || string.IsNullOrEmpty(keyValue); } // suppress clear on "real" rows IEnumerable <HyperLink> clearBtn = Caisis.UI.Core.Classes.PageUtil.GetControls <HyperLink>(e.Row).Where(btn => btn.CssClass.Contains("ClearGridRowLink")); if (!hasEmptyKeys) { clearBtn.ForEach(b => b.Style["display"] = "none"); } // suppress delete button on "fake" rows IEnumerable <ImageButton> deleteBtn = Caisis.UI.Core.Classes.PageUtil.GetControls <ImageButton>(e.Row).Where(btn => btn.CommandName == "Delete"); if (hasEmptyKeys) { deleteBtn.ForEach(b => b.Style["display"] = "none"); } // validate: LockedBy if (validateAuditField) { object lockedBy = getRowValue(BusinessObject.LockedBy); bool rowIsLocked = lockedBy != null && lockedBy + "" != ""; if (rowIsLocked) { // special case var fields = CICHelper.GetCaisisInputControlDictionary(e.Row); if (fields.ContainsKey(LabTest.LabClinicalSignificance)) { var input = fields[LabTest.LabClinicalSignificance]; input.PreRender += (a, b) => input.Enabled = true; } } } // c13-124 if (MatchProtocol("c13-124") && tableName == "Medications" && includeAnalgesicMedications.HasValue) { string medType = getRowValue(Medication.MedType) + ""; bool showRow = string.IsNullOrEmpty(medType) || (includeAnalgesicMedications.Value ? medType == "Analgesic" : medType != "Analgesic"); e.Row.Visible = showRow; } } }; gridsToValidate.Add(tableName, grid); grid.DataBind(); grid.DataKeyNames = null; // workaround for ControlState bogosity panel.Controls.Add(grid); panel.Controls.Add(addNewRowButton); container.Controls.Add(panel); }