I’m trying to delete item from database and then inform client about result.
- I get an id
- I send id to the data manager class
- I need to inform client about result
What the right way, to return success/unsuccess result from data manager?
Is it good to use bool and return true/false?
public bool Delete(int id) { var client = db.Clients.FirstOrDefault(x => x.Id == id); if (client == null) return false; db.Clients.Remove(client); db.SaveChanges(); return true; }
Or it’s better to use try/catch?
public void Delete(int id) { var client = db.Clients.FirstOrDefault(x => x.Id == id); db.Clients.Remove(client); db.SaveChanges(); } public JsonResult AddEmployee(int id) { try { itemManager.Delete(id); return Json(new { success }); } catch (Exception) { return Json(new { unsuccess }); } }