Exemplo n.º 1
0
        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;
                }
            }
        }
Exemplo n.º 2
0
        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;
                    }
                }
            }
        }
Exemplo n.º 3
0
 public ActionResult DeleteConfirmed(int id)
 {
     db.Delete(id);
     return(RedirectToAction("Index"));
 }