Example #1
0
        private void Register(StudentLessonEntity model)
        {
            model.IsRegistered     = true;
            model.RegistrationTime = DateTime.Now;
            this.LessonStudents.Remove(model);
            this.RegisteredStudents.Add(model);

            _db.ThrottleSave();
        }
        public StudentLessonViewModel(
            StudentEntity student,
            Dictionary <string, LessonEntity> lessonModels,
            IExportLocatorScope serviceLocator,
            IPageHost host,
            LocalDbContext context
            )
        {
            OpenStudentHandler = ReactiveCommand.Create(OpenStudent);
            OpenImageHandler   = ReactiveCommand.Create(LoadImage);
            this.Model         = student;
            ServiceLocator     = serviceLocator;
            this.FullName      = student.LastName + " " + student.FirstName;
            foreach (var keyValuePair in lessonModels)
            {
                var studentLessonModel =
                    keyValuePair.Value.StudentLessons?.FirstOrDefault(model => model._StudentId == student.Id) ??
                    new StudentLessonEntity {
                    _LessonId    = keyValuePair.Value.Id,
                    Lesson       = keyValuePair.Value,
                    Student      = student,
                    _StudentId   = student.Id,
                    IsRegistered = false,
                    Mark         = ""
                };
                if (studentLessonModel.Id == 0)
                {
                    context.StudentLessons.Add(studentLessonModel);
                    context.ThrottleSave();
                }

                this.LessonToLessonMark.Add(keyValuePair.Key,
                                            new StudentLessonMarkViewModel(studentLessonModel, context, host));
            }

            this.MissedLessons =
                this.LessonToLessonMark.Values.Aggregate(0,
                                                         (i, model) => model.StudentLesson.IsLessonMissed ? i + 1 : i);
        }