private void InsertOrUpdateUser(user user) { var id = user.userId; using (var db = new TimetableContext()) { if (db.users.Any(u => u.userId == id)) { db.users.Attach(user); db.Entry(user).State = System.Data.Entity.EntityState.Modified; } else { if (db.users.Where(u => u.username == user.username).FirstOrDefault() == null) { db.users.Add(user); } else { MessageBox.Show("Vartotojas vardu \"" + user.username + "\" jau yra"); } } db.SaveChanges(); } }
private void InsertOrUpdateTimetable(string username, int branchId, timetable time) { using (var db = new TimetableContext()) { var id = time.timetableId; if (db.timetables.Any(t => t.timetableId == id)) { db.timetables.Attach(time); db.Entry(time).State = System.Data.Entity.EntityState.Modified; } else { db.timetables.Add(time); } db.SaveChanges(); } }