public bool Delete(long id) { bool res = false; try { using (DataModel.DatabaseEntities db = new DataModel.DatabaseEntities()) { DataModel.tblItem item = db.tblItems.Where(x => x.ID == id).FirstOrDefault(); if (item != null) { db.tblItems.Remove(item); db.SaveChanges(); } } res = true; } catch { res = false; } return(res); }
public long Add(IItemDAO dao) { long id = 0; DataModel.tblItem item = new DataModel.tblItem(); item.Name = dao.Name; item.ParameterA = dao.ParameterA; item.ParameterB = dao.ParameterB; try { using (DataModel.DatabaseEntities db = new DataModel.DatabaseEntities()) { db.tblItems.Add(item); int i = db.SaveChanges(); id = item.ID; } } catch { id = 0; } return(id); }
public bool Update(IItemDAO dao) { bool res = false; try { using (DataModel.DatabaseEntities db = new DataModel.DatabaseEntities()) { DataModel.tblItem item = db.tblItems.Where(x => x.ID == dao.ID).FirstOrDefault(); if (item != null) { item.Name = dao.Name; item.ParameterA = dao.ParameterA; item.ParameterB = dao.ParameterB; int i = db.SaveChanges(); res = true; } } } catch { res = false; } return(res); }