Example #1
0
        public bool AddLessonBlock(Teacher t, Subject s, int blocksCount)
        {
            // Check whether or not this subject is full already.
            if (!IsSubjectFull(s,blocksCount)) {
                // Check if there are a SubjectDistBlock with this subject AND this teacher already! If there are - add to the blockscount! :-)
                SubjectDistBlock sdb = (from sb in SubjectDistBlocks
                                       where sb.Subject.Equals(s) && sb.Teacher.Equals(t)
                                       select sb).FirstOrDefault();

                if (sdb != null)
                {
                    // Already exists!
                    sdb.BlocksCount += blocksCount;
                }
                else
                {
                    // Create new!
                    SubjectDistBlocks.Add(new SubjectDistBlock { Teacher = t, Subject = s, BlocksCount = blocksCount });
                }
                return true;
            }
            return false;
        }
Example #2
0
        public bool IsSubjectFull(Subject s, int tryingToAdd = 1)
        {
            var subjectDistBlocks = from sdb in SubjectDistBlocks
                                    where sdb.Subject.Equals(s)
                                    select sdb;

            int highestBlocksCount = Semester.Blocks.SingleOrDefault(x => x.Subject.Equals(s)).BlocksCount;
            int totalBlocksCount = 0;
            foreach (SubjectDistBlock sdb in subjectDistBlocks)
            {
                totalBlocksCount += sdb.BlocksCount;
            }
            Console.WriteLine(subjectDistBlocks.Count());
            return (totalBlocksCount + tryingToAdd) > highestBlocksCount;
        }