コード例 #1
0
        public ICommandResult Handle(CreateClassroomCommand command)
        {
            //Fail Fast validations
            command.Validate();
            if (command.Invalid)
            {
                AddNotifications(command);
                return(new ClassroomCommandResult(false, "Erro ao vincular aula ao aluno", Notifications));
            }

            // Cria a entidade
            var classroom = new Classroom(command.Start, command.End, command.DayOfWeek);

            //adiciona validações
            AddNotifications(classroom);
            if (Invalid)
            {
                return(new ClassroomCommandResult(false, "Erro ao criar a aula.", classroom.Notifications));
            }

            //persiste no banco
            _repository.AddClassroom(classroom);


            //retorna com sucesso
            return(new ClassroomCommandResult(true, "Aula criada com sucesso", new { Id = classroom.Id }));
        }
コード例 #2
0
        public IActionResult ProfScreen(ProfScreenViewModel profScreenViewModel)
        {
            _classroomRepository.AddClassroom(profScreenViewModel.classroom);
            List <string> roster = new List <string>();

            if (profScreenViewModel.roster != null)
            {
                roster = iformreader.ReadAsList(profScreenViewModel.roster);
            }
            foreach (string input in roster)
            {
                if (input != "\"identifier\",\"github_username\",\"github_id\",\"name\"")
                {
                    string[] line = input.Split(',');

                    // only input students that have connected to github classroom
                    if (line[1].Trim('"') != "")
                    {
                        // get the student username and id set by the teacher.
                        if (line[3].Trim('"') == "")
                        {
                            // Students.Add(new Student(line[0].Trim('"'), line[1].Trim('"'), line[0].Trim('"')));
                            Models.Students.Student student = new Models.Students.Student()
                            {
                                githubEmail   = line[0].Trim('"'),
                                githubUrsName = line[1].Trim('"'),
                                name          = line[0].Trim('"'),
                                classId       = profScreenViewModel.classroom.classId
                            };
                            _studentRepository.AddStudent(student);
                        }
                        else
                        {
                            // Students.Add(new Student(line[3].Trim('"'), line[1].Trim('"'), line[0].Trim('"')));
                            Models.Students.Student student = new Models.Students.Student()
                            {
                                githubEmail   = line[0].Trim('"'),
                                githubUrsName = line[1].Trim('"'),
                                name          = line[3].Trim('"'),
                                classId       = profScreenViewModel.classroom.classId
                            };
                            _studentRepository.AddStudent(student);
                        }
                    }
                }
            }
            var classes  = _classroomRepository.GetAllClassrooms().OrderBy(c => c.className);
            var students = _studentRepository.GetAllStudents().OrderBy(s => s.classId);

            profScreenViewModel = new ProfScreenViewModel()
            {
                Classrooms = classes.ToList(),
                Students   = students.ToList()
            };
            return(View(profScreenViewModel));
        }