// update public bool UpdateLessonAttending(int id, LessonAttendingModel lesoonAttending) { using (AttenderEntities ef = new AttenderEntities()) { LessonAttending updateLessonAttending = ef.LessonAttendings.FirstOrDefault(a => a.Id == id); if (updateLessonAttending == null) { return(false); } updateLessonAttending.LessonId = lesoonAttending.LessonId; updateLessonAttending.StudentId = lesoonAttending.StudentId; updateLessonAttending.CheckTimeStart = lesoonAttending.CheckTimeStart; updateLessonAttending.CheckTimeEnd = lesoonAttending.CheckTimeEnd; try { ef.SaveChanges(); } catch { return(false); } } return(true); }
// Create; public bool AddLessonAttending(LessonAttendingModel newLessonAttending) { using (AttenderEntities ef = new AttenderEntities()) { LessonAttending lessonAttending = new LessonAttending() { //Id = newLessonAttending.Id, LessonId = newLessonAttending.LessonId, StudentId = newLessonAttending.StudentId, CheckTimeStart = newLessonAttending.CheckTimeStart, CheckTimeEnd = newLessonAttending.CheckTimeEnd }; ef.LessonAttendings.Add(lessonAttending); try { ef.SaveChanges(); } catch { return(false); } } return(true); }
public LessonAttendingModel GetLessonAttendingById(int id) { LessonAttendingModel lessonAttending = null; using (AttenderEntities ef = new AttenderEntities()) { LessonAttending item = ef.LessonAttendings.FirstOrDefault(a => a.Id == id); if (item != null) { lessonAttending = new LessonAttendingModel() { Id = item.Id, LessonId = item.LessonId, StudentId = item.StudentId, CheckTimeStart = item.CheckTimeStart, CheckTimeEnd = item.CheckTimeEnd }; } } return(lessonAttending); }
// delete public bool DeleteLessonAttending(int id) { using (AttenderEntities ef = new AttenderEntities()) { LessonAttending deletedLessonAttending = ef.LessonAttendings.FirstOrDefault(a => a.Id == id); if (deletedLessonAttending == null) { return(false); } ef.LessonAttendings.Remove(deletedLessonAttending); try { ef.SaveChanges(); } catch { return(false); } } return(true); }