public static int Delete(params object[] id) { var db = new DBcon <T>(); var Table = db.Table.Find(id); Table.UpdateDate = DateTime.Now; Table.Deleted = true; return(db.SaveChanges()); }
public static int UpdateRange(IEnumerable <T> tables) { var db = new DBcon <T>(); foreach (var table in tables) { db.Entry(table).State = EntityState.Modified; } return(db.SaveChanges()); }
public static int DeleteRange(IEnumerable <T> ids) { var db = new DBcon <T>(); foreach (var id in ids) { var Table = db.Table.Find(id); Table.Deleted = true; } return(db.SaveChanges()); }
public static int AddRange(List <T> tables) { var db = new DBcon <T>(); foreach (var table in tables) { if (string.IsNullOrEmpty(table.UserID)) { throw new Exception("UserID empty you must enter valid UserID"); } table.CreateDate = DateTime.Now; table.UpdateDate = DateTime.Now; table.Deleted = false; } db.Table.AddRange(tables); return(db.SaveChanges()); }
public static int Update(T model) { var db = new DBcon <T>(); var db2 = new DBcon <T>(); var data = db2.Table.Find(model.ID); if (data != null && data.Deleted != true) { model.UpdateDate = DateTime.Now; model.CreateDate = data.CreateDate; model.UserID = data.UserID; db.Entry(model).State = EntityState.Modified; return(db.SaveChanges()); } else { throw new DataStoreException("We can't find the selected data to update"); } }
public static int Add(T model) { if (string.IsNullOrEmpty(model.UserID) && typeof(T).Name != "Logger") { throw new DataStoreException("UserID Null"); } var db = new DBcon <T>(); model.CreateDate = DateTime.Now; model.UpdateDate = DateTime.Now; model.Deleted = false; db.Table.Add(model); try { return(db.SaveChanges()); } catch (Exception ex) { ExceptionHandler.GetLog(ex, model.UserID, LoggerModels.ExcptionType.UnknownError); throw new DataStoreException("UnKnown exception please look at the InnerException", ex); } }