private void ProcessForm(int categoryId, bool isDelete)
        {
            try
            {
                using (TransactionScope ts = new TransactionScope())
                {
                    CategoryBO objCategory = new CategoryBO(this.ObjContext);
                    if (categoryId > 0)
                    {
                        objCategory.ID = categoryId;
                        objCategory.GetObject();
                        objCategory.Name        = this.txtCategoryName.Text;
                        objCategory.Description = this.txtDescription.Text;

                        if (isDelete)
                        {
                            objCategory.Delete();
                        }
                    }
                    else
                    {
                        objCategory.Name        = this.txtCategoryName.Text;
                        objCategory.Description = this.txtDescription.Text;
                        objCategory.Add();
                    }

                    this.ObjContext.SaveChanges();
                    ts.Complete();
                }
            }
            catch (Exception ex)
            {
                //throw ex;
            }
        }
Exemple #2
0
        private void btnDelete_Click(object sender, EventArgs e)
        {
            if (dgvMain.SelectedRows.Count >= 1)
            {
                DialogResult dr = MessageBox.Show("Are you serious?", "BE CAREFUL", MessageBoxButtons.YesNo);
                if (dr == DialogResult.Yes)
                {
                    var  rows      = dgvMain.SelectedRows;
                    bool isSuccess = false;
                    switch (CurrentPoco)
                    {
                    case CurrentPoco.Shipper:
                        for (int i = 0; i < rows.Count; i++)
                        {
                            var       s  = rows[i].DataBoundItem as Shipper;
                            ShipperBO sb = new ShipperBO();
                            if (sb.Delete(s.ShipperID))
                            {
                                isSuccess = true;
                            }
                        }
                        break;

                    case CurrentPoco.Category:
                        for (int i = 0; i < rows.Count; i++)
                        {
                            var        c  = rows[i].DataBoundItem as Category;
                            CategoryBO cb = new CategoryBO();
                            if (cb.Delete(c.CategoryID))
                            {
                                isSuccess = true;
                            }
                        }
                        break;

                    default:
                        break;
                    }
                    if (isSuccess)
                    {
                        MessageBox.Show("Successful");
                    }
                    else
                    {
                        MessageBox.Show("Error");
                    }
                }
            }
        }
        public IActionResult Delete(int id)
        {
            CategoryBO   categoryBO;
            ObjectResult response;

            try
            {
                _log.LogInformation($"Starting Delete( {id} )");

                categoryBO = new CategoryBO(_loggerFactory, _config);
                categoryBO.Delete(id);

                response = Ok(string.Empty);

                _log.LogInformation($"Finishing Delete( {id} )");
            }
            catch (Exception ex)
            {
                _log.LogError(ex.Message);
                response = StatusCode(500, ex.Message);
            }

            return(response);
        }
 public ActionResult Delete(int id)
 {
     cbo.Delete(id);
     return(RedirectToAction("Index", "Category"));
 }