public CreateNewLessonsViewModel(User currentUser) { CurrentUser = currentUser; RevertToPreviousViewModelCmd = new RelayCommand((p) => ViewModelManager.Instance.ReturnToPreviousModel()); AddNewLessonCmd = new RelayCommand((p) => StartAddingNewLesson(), (p) => CanStartAddingNewLesson()); ShowLessonCmd = new RelayCommand((p) => ShowLesson(), (p) => CurrentLesson != null); SaveLessonCmd = new RelayCommand((p) => SaveLesson(), (p) => CanSaveLesson()); DeleteSelectedWordCmd = new RelayCommand((p) => CurrentLessonWords.Remove(CurrentEditingWord), (p) => CurrentEditingWord != null && CurrentLessonWords.Count() > 1); AddNewWordToLessonCmd = new RelayCommand((p) => AddNewWordToLesson(), (p) => CanAddNewWordToLesson()); DeleteSelectedLessonCmd = new RelayCommand((p) => DeleteSelectedLesson(p), (p) => CanDeleteSelectedLesson(p)); using (var db = Database.Instance.GetConnection()) { Lessons = new ObservableCollection <Lesson>(); foreach (var lesson in db.Table <Lesson>().Where(lesson => lesson.UserId == currentUser.Id)) { Lessons.Add(lesson); } } _langNameValidationService = new ValidateLanguageDefinitionService(); _newLessonValidationService = (p) => { var ret = new List <string>(); int count; using (var db = Database.Instance.GetConnection()) { count = db.Table <Lesson>().Where(l => l.UserId == currentUser.Id && l.Name.Equals(p)).Count(); } if (count >= 1 || (CurrentLesson != null && CurrentLesson.Name.Equals(p as string))) { ret.Add("Lesson name has to be unique"); } else if ((p as string).Length < Constants.MinLessonNameLength || (p as string).Length > Constants.MaxLessonNameLength) { ret.Add(String.Format("Length has to be between {0} and {1}", Constants.MinLessonNameLength, Constants.MaxLessonNameLength)); } return(ret); }; ShowModifyLessonSubView = false; CurrentLessonWords = new ObservableCollection <Word>(); CurrentEditingWord = new Word() { }; CurrentLessonWords.CollectionChanged += CurrentLessonWords_CollectionChanged; CurrentLessonWordsChanged = false; }
public Lesson() { _langNameValidatorService = new ValidateLanguageDefinitionService(); }