Пример #1
0
 private void DeleteProduct( Product product )
 {
     //Confirm
     if (MessageBox.Show (this, $"Are you sure you want to delete '{product.Name}'?",
                         "Delete", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
         return;
     else
     {
         try
         {
             //Delete product
             _database.Remove (product.Id);
             UpdateList ();
         } catch (ArgumentException ex)
         {
             MessageBox.Show (ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
         } catch (ValidationException ex)
         {
             MessageBox.Show (ex.Message, "Validation Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
         } catch (Exception)
         {
             MessageBox.Show ("Save failed", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
         }
     }
 }
Пример #2
0
        public IActionResult Delete(ProductModel model)
        {
            try
            {
                var product = _database.GetAll().FirstOrDefault(p => p.Id == model.Id);

                _database.Remove(model.Id);

                return(RedirectToAction(nameof(Index)));
            } catch (Exception e)
            {
                ModelState.AddModelError("", e.Message);
            };

            return(View(model));
        }
Пример #3
0
        public ActionResult Delete(int id)
        {
            try
            {
                var product = _database.GetAll().FirstOrDefault(p => p.Id == id);

                if (product == null)
                {
                    return(HttpNotFound());
                }

                _database.Remove(id);

                return(Content(""));
            } catch (Exception e)
            {
                ModelState.AddModelError("", e.Message);
            }

            return(Json(ModelState, JsonRequestBehavior.AllowGet));
        }