示例#1
0
 public Zajecia getSlot(Zajecia other)
 {
     if (isSlotOccupied(other))
     {
         return(activities.Find(x => x.Equals(other)));
     }
     return(null);
 }
示例#2
0
        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;
            }
        }
示例#3
0
 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();
 }
示例#4
0
        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);
        }
示例#5
0
        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);
        }
示例#6
0
        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();
        }
示例#7
0
 public void emptySlot(Zajecia other)
 {
     activities.Remove(getSlotByID(other.activityID));
     //if (isSlotOccupied(other)) activities.Remove(getSlot(other));
 }
示例#8
0
 public bool isSlotOccupied(Zajecia other)
 {
     return(activities.Contains(other));
 }