void Grid_RowsChanging(object sender, GridViewCollectionChangingEventArgs e) { if (e.Action == Telerik.WinControls.Data.NotifyCollectionChangedAction.Remove) { objMaster = new CompanyBO(); try { objMaster.GetByPrimaryKey(grdLister.CurrentRow.Cells["Id"].Value.ToInt()); objMaster.Delete(objMaster.Current); } catch (Exception ex) { if (objMaster.Errors.Count > 0) { ENUtils.ShowMessage(objMaster.ShowErrors()); } else { ENUtils.ShowMessage(ex.Message); } e.Cancel = true; } } }
protected void btnDelete_Click(object sender, EventArgs e) { { int companyId = int.Parse(hdnSelectedCompanyID.Value.Trim()); if (companyId > 0) { try { using (TransactionScope ts = new TransactionScope()) { CompanyBO objCompany = new CompanyBO(this.ObjContext); objCompany.ID = companyId; objCompany.GetObject(); List <UserBO> lstUsers = objCompany.UsersWhereThisIsCompany; foreach (UserBO user in lstUsers) { UserBO objUser = new UserBO(this.ObjContext); objUser.ID = user.ID; objUser.GetObject(); objUser.Delete(); } List <ClientBO> lstClient = objCompany.ClientsWhereThisIsDistributor; foreach (ClientBO client in lstClient) { ClientBO objClient = new ClientBO(this.ObjContext); objClient.ID = client.ID; objClient.GetAllObject(); objClient.Delete(); } objCompany.Delete(); this.ObjContext.SaveChanges(); ts.Complete(); this.PopulateDataGrid(); } } catch (Exception ex) { throw ex; } } } }
public ActionResult DeleteConfirmed(int id) { db.Delete(id); return(RedirectToAction("Index")); }