示例#1
0
        public TimetableModel GetTeacherTimetable(Guid teacherId)
        {
            if (teacherId == null)
            {
                throw new ArgumentNullException("teacherId");
            }

            TeacherDivision teacherDivision = this.UnitOfWork.TeacherDivisionRepository.GetByTeacherId(teacherId);

            if (teacherDivision == null)
            {
                throw new InvalidOperationException("Teacher has not assigned to this semester.");
            }

            Timetable tt = null;

            if (teacherDivision.Timetable != null)
            {
                tt = teacherDivision.Timetable;
            }
            else
            {
                tt = this.UnitOfWork.TeacherDivisionRepository.CreateTeacherTimetable(teacherDivision.Id, ShiftPerDay, SlotPerShift);
                this.UnitOfWork.SaveChanges();
            }

            TimetableModel ttModel = Mapper.Map <Schedule.Models.Timetable, StoneCastle.Scheduler.Models.TimetableModel>(tt);

            ttModel = this.CreateTimetableMatrix(ttModel);

            return(ttModel);
        }
示例#2
0
        public Models.Teacher CreateTeacher(Guid divisionId, string firstName, string lastName, string email, string phone, string highlightColor, bool isActive)
        {
            Division division = this.DataContext.Get <Division>().Where(x => x.Id == divisionId).FirstOrDefault();

            if (division == null)
            {
                throw new InvalidOperationException($"Division ({divisionId}) does not exist.");
            }

            if (String.IsNullOrEmpty(highlightColor))
            {
                Random rand = new Random();
                highlightColor = Commons.Ultility.GetHighlightColor(rand);
            }
            Models.Profile profile = new Models.Profile()
            {
                Id             = Guid.NewGuid(),
                FirstName      = firstName,
                LastName       = lastName,
                Email          = email,
                Phone          = phone,
                HighlightColor = highlightColor,
                IsDeleted      = false
            };

            Models.Account account = new Models.Account()
            {
                Id        = Guid.NewGuid(),
                Profile   = profile,
                IsActive  = isActive,
                IsDeleted = false
            };

            Models.Teacher teacher = new Models.Teacher()
            {
                Id        = Guid.NewGuid(),
                Account   = account,
                IsActive  = isActive,
                IsDeleted = false,
            };

            TeacherDivision teacherDivision = new TeacherDivision()
            {
                Id         = Guid.NewGuid(),
                TeacherId  = teacher.Id,
                DivisionId = divisionId
            };

            teacher.TeacherDivisions.Add(teacherDivision);

            this.DataContext.Insert <Models.Profile>(profile);
            this.DataContext.Insert <Models.Account>(account);
            this.DataContext.Insert <Models.Teacher>(teacher);
            this.DataContext.Insert <TeacherDivision>(teacherDivision);

            return(teacher);
        }
        public TeacherDivision GetByTeacherId(Guid teacherId)
        {
            if (teacherId == null)
            {
                throw new System.ArgumentNullException("TeacherId");
            }

            TeacherDivision teacherDivision = this.GetAll().Where(x => x.TeacherId == teacherId).FirstOrDefault();

            return(teacherDivision);
        }
        public Timetable CreateTeacherTimetable(Guid id, int shiftPerDay, int slotPerShift)
        {
            TeacherDivision teacherDivision = this.GetById(id);

            if (teacherDivision == null)
            {
                throw new InvalidOperationException($"Teacher Division ({id}) does not exist.");
            }

            Timetable tt = new Timetable()
            {
                Id             = Guid.NewGuid(),
                ShiftPerDay    = shiftPerDay,
                SlotPerShift   = slotPerShift,
                HighlightColor = Commons.Ultility.GetHighlightColor(new Random())
            };

            teacherDivision.TimetableId = tt.Id;
            this.DataContext.Insert <Timetable>(tt);
            this.DataContext.Update <TeacherDivision, Guid>(teacherDivision, x => x.TeacherId);
            return(tt);
        }
示例#5
0
        public Models.Teacher UpdateTeacher(Guid id, Guid divisionId, string firstName, string lastName, string email, string phone, string highlightColor, bool isActive)
        {
            Models.Teacher teacher = this.GetById(id);

            if (teacher == null)
            {
                throw new InvalidOperationException($"Teacher ({id}) does not exist.");
            }

            teacher.IsActive = isActive;

            Division division = this.DataContext.Get <Division>().Where(x => x.Id == divisionId).FirstOrDefault();

            if (division == null)
            {
                throw new InvalidOperationException($"Division ({divisionId}) does not exist.");
            }

            if (teacher.TeacherDivisions.Count(x => x.DivisionId == divisionId) <= 0)
            {
                // Remove existing
                teacher.TeacherDivisions.Clear();

                // Add
                TeacherDivision teacherDivision = new TeacherDivision()
                {
                    Id         = Guid.NewGuid(),
                    TeacherId  = teacher.Id,
                    DivisionId = division.Id
                };

                teacher.TeacherDivisions.Add(teacherDivision);
            }

            Models.Account account = this.DataContext.Get <Models.Account>().Where(x => x.Id == teacher.AccountId).FirstOrDefault();

            if (account == null)
            {
                throw new InvalidOperationException($"Account ({teacher.AccountId}) does not exist.");
            }

            account.IsActive = isActive;

            Models.Profile profile = this.DataContext.Get <Models.Profile>().Where(x => x.Id == account.ProfileId).FirstOrDefault();

            if (profile == null)
            {
                throw new InvalidOperationException($"Profile ({account.ProfileId}) does not exist.");
            }

            if (String.IsNullOrEmpty(highlightColor))
            {
                Random rand = new Random();
                highlightColor = Commons.Ultility.GetHighlightColor(rand);
            }
            profile.FirstName      = firstName;
            profile.LastName       = lastName;
            profile.Email          = email;
            profile.Phone          = phone;
            profile.HighlightColor = highlightColor;

            this.DataContext.Update <Models.Profile, Guid>(profile, x => x.FirstName, x => x.LastName, x => x.Email, x => x.Phone);
            this.DataContext.Update <Models.Account, Guid>(account, x => x.IsActive);
            this.DataContext.Update <Models.Teacher, Guid>(teacher, x => x.IsActive);

            return(teacher);
        }