public static void DeleteKnowledge(InfoId toDel) { using (var dbContext = new QuickToDosEntities()) { Knowledge aKnowledge = dbContext.Knowledges.Find(toDel.Id); if (aKnowledge == null) { throw new Exception("Echec mise a jour"); } dbContext.Knowledges.Remove(aKnowledge); dbContext.SaveChanges(); } }
public static int AddKnowledge(KnowAdd Know) { if (Know.Id == -1) { using (var dbContext = new QuickToDosEntities()) { var aKnowledge = new Knowledge { Subject = Know.Subject, Body = Know.Body, Creation = DateTime.Now }; dbContext.Knowledges.Add(aKnowledge); dbContext.SaveChanges(); Know.Id = aKnowledge.Id; } } else { using (var dbContext = new QuickToDosEntities()) { Knowledge aKnowledge = dbContext.Knowledges.Find(Know.Id); if (aKnowledge == null) { throw new Exception("Echec mise a jour"); } aKnowledge.Subject = Know.Subject; aKnowledge.Body = Know.Body; aKnowledge.Modification = DateTime.Now; dbContext.SaveChanges(); } } return(Know.Id); }