public sTag DeleteSTag(sTag tag) { return tagAccessor.DeleteSTag(tag); }
public sTag UpdateSTag(sTag tag) { return tagAccessor.UpdateSTag(tag); }
//set parentId to 0 when it is at the top level public sTag CreateSTag(int parentId, string value) { sTag tag = new sTag(); tag.value = value; tag.parentId = parentId; try { VestnDB db = new VestnDB(); db.sTag.Add(tag); db.SaveChanges(); } catch (InvalidOperationException) { return null;//bad id } return (tag); }
private sTag GetEntitySTag(string value) { VestnDB db = new VestnDB(); sTag tag = new sTag(); try { tag = db.sTag.Where(u => u.value == value).First(); } catch (Exception e) { return null; } return tag; }
public sTag UpdateSTag(sTag tag) { sTag oldTag = GetSTag(tag.id); if (oldTag.value != tag.value) { return tag; } try { VestnDB db = new VestnDB(); db.Entry(tag).State = EntityState.Modified; db.SaveChanges(); } catch (InvalidOperationException) { return null; } return tag; }
public sTag DeleteSTag(sTag tag) { VestnDB db = new VestnDB(); db.sTag.Attach(tag); tag = db.sTag.Remove(tag); db.SaveChanges(); return tag; }