// private DecoderContext db = new DecoderContext(); public int? AddDecoder(Decoder decoder) { DecoderContext db = null; try { db = new DecoderContext(); decoder.UpdateFieldsFromXml(); db.Decoders.Add(decoder); db.SaveChanges(); return decoder.Id; } finally { db?.Dispose(); } }
public void DeleteDecoder(int? id) { DecoderContext db = null; try { db = new DecoderContext(); var decoder = db.Decoders.Find(id); if (decoder != null) { db.Decoders.Remove(decoder); db.SaveChanges(); } else { throw new KeyNotFoundException("L'ID envoyée ne correspond à aucun décodeur dans la base de donnée"); } } finally { db?.Dispose(); } }
public bool UpdateDecoder(Decoder updatedDecoder) { DecoderContext db = null; var mustRefreshToolbox = false; try { db = new DecoderContext(); updatedDecoder.UpdateFieldsFromXml(); var decoder = db.Decoders.Find(updatedDecoder.Id); if (decoder != null) { /*decoder.Name = updatedDecoder.Name; decoder.Version = updatedDecoder.Version; decoder.Category = updatedDecoder.Category; decoder.Tags = updatedDecoder.Tags; decoder.Xml = updatedDecoder.Xml; decoder.Code = updatedDecoder.Code; decoder.FrenchSpec = updatedDecoder.FrenchSpec; decoder.UpdateFieldsFromXml();*/ if (decoder.Name != updatedDecoder.Name || decoder.Version != updatedDecoder.Version || decoder.Category != updatedDecoder.Category || decoder.Parameters != updatedDecoder.Parameters || decoder.Tags != updatedDecoder.Tags || decoder.Editable != updatedDecoder.Editable) { mustRefreshToolbox = true; } //TODO DO NOT OVERRIDE CODE AND SPEC db.Entry(decoder).CurrentValues.SetValues(updatedDecoder); db.SaveChanges(); return mustRefreshToolbox; } else { throw new KeyNotFoundException(); } } finally { db?.Dispose(); } }