public static void AddBehaviorToStudent(Student s, BehaviorType b, DateTime date) { using (var context = new Entities()) { BehaviorPerformed behavior = new BehaviorPerformed { BPID = GenerateBPID(), BP_Date = date, behaviorID = b.behaviorID, studentID = s.StudentID }; context.Set <BehaviorPerformed>().Add(behavior); context.SaveChanges(); } }
public static void SaveBehavior(BehaviorType bt) { using (var context = new Entities()) { var recordToUpdate = from b in context.BehaviorType where b.behaviorID == bt.behaviorID select b; List <BehaviorType> records = recordToUpdate.ToList(); if (recordToUpdate.Count() > 0) { BehaviorType old = records.FirstOrDefault(); context.Entry(old).CurrentValues.SetValues(bt); } else { context.Set <BehaviorType>().Add(bt); } context.SaveChanges(); } }