Exemplo n.º 1
0
        /// <summary>
        /// Method that edits a student's note from list in parent view model if input data is valid.
        /// </summary>
        private void EditStudent()
        {
            var validator = new StudentNoteValidator();

            // Not valid data messages.
            if (!validator.CheckFirstName(InputFirstName))
            {
                MessageBox.Show(AssemblyInfo.ADD_STUDENT_DENIED + AssemblyInfo.ADD_DENIED_INCORRECT_FIRSTNAME);
            }
            else if (!validator.CheckLastName(InputLastName))
            {
                MessageBox.Show(AssemblyInfo.ADD_STUDENT_DENIED + AssemblyInfo.ADD_DENIED_INCORRECT_LASTNAME);
            }
            else if (!validator.CheckAge(InputAge))
            {
                MessageBox.Show(AssemblyInfo.ADD_STUDENT_DENIED + AssemblyInfo.ADD_DENIED_INCORRECT_AGE);
            }
            // Input data is valid.
            else
            {
                // Finding student's note in list by Id from parent window view model.
                Student editStudent   = App.WindowService.MainWindowViewModel.StudentsData.First(x => x.Id == InputId);
                int     editStudentId = App.WindowService.MainWindowViewModel.StudentsData.IndexOf(editStudent);
                App.WindowService.MainWindowViewModel.StudentsData[editStudentId] = new Student(InputId, InputFirstName,
                                                                                                InputLastName, InputAge, InputGender);
                MessageBox.Show(AssemblyInfo.EDIT_STUDENT_SUCCESS);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Method that adds a new student's note to list in parent view model if input data is valid.
        /// </summary>
        private void AddStudent()
        {
            var validator = new StudentNoteValidator();

            // Not valid data messages.
            if (!validator.CheckFirstName(InputFirstName))
            {
                MessageBox.Show(AssemblyInfo.ADD_STUDENT_DENIED + AssemblyInfo.ADD_DENIED_INCORRECT_FIRSTNAME);
            }
            else if (!validator.CheckLastName(InputLastName))
            {
                MessageBox.Show(AssemblyInfo.ADD_STUDENT_DENIED + AssemblyInfo.ADD_DENIED_INCORRECT_LASTNAME);
            }
            else if (!validator.CheckAge(InputAge))
            {
                MessageBox.Show(AssemblyInfo.ADD_STUDENT_DENIED + AssemblyInfo.ADD_DENIED_INCORRECT_AGE);
            }
            // Input data is valid.
            else
            {
                Student newStudentNote = new Student(
                    App.WindowService.MainWindowViewModel.StudentsData.Count,
                    InputFirstName,
                    InputLastName,
                    InputAge,
                    InputGender);

                // Check the new note for existing in list.
                // If the list doesn't contain the new note, add it to list.
                if (App.WindowService.MainWindowViewModel.StudentsData
                    .FirstOrDefault(x => { return(x.AreEqual(newStudentNote)); }) == null)
                {
                    App.WindowService.MainWindowViewModel.StudentsData.Add(newStudentNote);
                    MessageBox.Show(AssemblyInfo.ADD_STUDENT_SUCCESS);
                }
                else
                {
                    MessageBox.Show(AssemblyInfo.ADD_STUDENT_DENIED + AssemblyInfo.ADD_DENIED_NOTE_EXIST);
                }
            }
        }