public Zajecia getSlot(Zajecia other) { if (isSlotOccupied(other)) { return(activities.Find(x => x.Equals(other))); } return(null); }
public ZajeciaDB(Zajecia other) { using (var db = new MyContext()) { room = other.room != null?db.rooms.SingleOrDefault(t => t.name == other.room).RoomID : 0; group = db.groups.SingleOrDefault(t => t.name == other.group).GroupID; subject = other.@class != null?db.subjects.SingleOrDefault(t => t.name == other.@class).SubjectID : 0; teacher = db.teachers.SingleOrDefault(t => t.name == other.teacher).TeacherID; slot = other.slot; } }
public void deleteSlot(Zajecia toDelete) { if (!data.isSlotOccupied(toDelete)) { return; } data.activities.Remove(data.getSlot(toDelete)); using (var db = new MyContext()) { db.activities.Remove(db.activities.Find(toDelete.activityID)); db.SaveChanges(); } //saveData(); }
public string getSlotTeachers(int slot) { if (selectedItem == null) { selectedItem = data.teachers[0]; } if (!data.isSlotOccupied(slot, "", "", selectedItem)) { return(" "); } Zajecia zajecia = data.getSlot(slot, "", "", selectedItem); if (zajecia.teacher != selectedItem) { return(" "); } return(zajecia.room + " " + zajecia.@class + " " + zajecia.group); }
public string getSlotRooms(int slot) { if (selectedItem == null) { selectedItem = data.rooms[0]; } if (!data.isSlotOccupied(slot, selectedItem)) { return(" "); } Zajecia zajecia = data.getSlot(slot, selectedItem); if (zajecia.room != selectedItem) { return(" "); } return(zajecia.group); }
public void changeSlot(Zajecia toChange) { ZajeciaDB toAdd = new ZajeciaDB(toChange); checkAssignment(toAdd); if (data.isSlotOccupied(toChange)) { throw new Exception("1"); } else { data.activities.Add(toChange); using (var db = new MyContext()) { mutex.WaitOne(); if (db.activities.Join(db.assignments, activity => new Tuple <int, int>(activity.GroupID, activity.SubjectID), assignment => new Tuple <int, int>(assignment.GroupID, assignment.SubjectID), (activity, assignment) => new { SlotID = activity.SlotID, GroupID = activity.GroupID, RoomID = activity.RoomID, TeacherID = assignment.TeacherID, }).Any(act => act.SlotID == toAdd.slot && (act.GroupID == toAdd.group || act.RoomID == toAdd.room || act.TeacherID == toAdd.teacher))) { mutex.ReleaseMutex(); throw new Exception("1"); } db.activities.Add(new Activity() { SubjectID = toAdd.subject, GroupID = toAdd.group, RoomID = toAdd.room, SlotID = toAdd.slot }); db.SaveChanges(); mutex.ReleaseMutex(); } } //saveData(); }
public void emptySlot(Zajecia other) { activities.Remove(getSlotByID(other.activityID)); //if (isSlotOccupied(other)) activities.Remove(getSlot(other)); }
public bool isSlotOccupied(Zajecia other) { return(activities.Contains(other)); }