public Result Handle(StudentInviteCommand command)
 {
     command.Student.AddInvite(new Data.Entities.Invite(command.Student.Id, command.Token, false, command.Student.Email));
     _context.Students.Update(command.Student);
     _context.SaveChanges();
     return(Result.Ok());
 }
            public Result Handle(AddExerciseCommand command)
            {
                var exercise = new Exercise(command.Name, command.UnitId, command.Comment);

                _context.Exercises.Add(exercise);
                _context.SaveChanges();
                return(Result.Ok());
            }
Beispiel #3
0
            public Result Handle(TeacherRegistrationCommand command)
            {
                var registration = new TeacherRegistration(command.Token, false, command.Email);

                _context.Registrations.Add(registration);
                _context.SaveChanges();
                return(Result.Ok(value: registration.Id));
            }
Beispiel #4
0
            public Result Handle(AddUnitCommand command)
            {
                var unit = Unit.CreateTimeUnit(command.Name);

                _context.Units.Add(unit);
                _context.SaveChanges();
                return(Result.Ok());
            }
            public Result Handle(AddClassCommand command)
            {
                var schoolClass = new SchoolClass(command.Name);

                _context.Classes.Add(schoolClass);
                _context.SaveChanges();
                return(Result.Ok());
            }
            public CSharpFunctionalExtensions.Result Handle(EditAddStudentCommand command)
            {
                var student = _context.Students.Find(command.Id);

                if (student == null)
                {
                    student = new Data.Entities.Student();
                    _context.Students.Add(student);
                    _context.SaveChanges();
                }

                if (!string.IsNullOrWhiteSpace(command.StudentCardNumber))
                {
                    student.StudentCardNumber = command.StudentCardNumber;
                }

                if (command.Gender.HasValue)
                {
                    student.Gender = command.Gender.Value;
                }

                if (!string.IsNullOrWhiteSpace(command.Email))
                {
                    student.Email = command.Email;
                }

                if (!string.IsNullOrWhiteSpace(command.Name))
                {
                    student.Name = command.Name;
                }

                if (command.SchoolClassId.HasValue)
                {
                    student.SchoolClassId = command.SchoolClassId.Value;
                }

                if (command.ShouldResultsBeHidden.HasValue)
                {
                    student.HiddenResults = command.ShouldResultsBeHidden.Value;
                }

                _context.Students.Update(student);
                _context.SaveChanges();
                return(Result.Ok());
            }
Beispiel #7
0
            public Result Handle(EditAppUserCommand command)
            {
                var user = command.User;

                command.User.HideResults = command.HideResults;
                _context.Persons.Update(user);
                _context.SaveChanges();
                return(Result.Ok());
            }
Beispiel #8
0
            public Result Handle(UserRegisteredCommand command)
            {
                var student = command.Student;

                student.MarkInviteUsed();
                _context.Students.Update(command.Student);
                _context.SaveChanges();
                return(Result.Ok());
            }
Beispiel #9
0
            public CSharpFunctionalExtensions.Result Handle(EditResultCommand command)
            {
                var result = _context.Results.Find(command.Id);

                if (result == null)
                {
                    return(CSharpFunctionalExtensions.Result.Fail("Sellist tulemust ei leitud"));
                }
                result.ChangeResultValue(command.ResultValue);
                _context.Results.Update(result);
                _context.SaveChanges();
                return(CSharpFunctionalExtensions.Result.Ok());
            }
Beispiel #10
0
        public async Task SeedAsync()
        {
//            _ctx.Database.EnsureDeleted();

            _ctx.Database.EnsureCreated();

            await SeedApplicationUsers();


            if (!_ctx.Units.Any())
            {
                AddUnits();
                _ctx.SaveChanges();
            }

            if (!_ctx.Exercises.Any())
            {
                AddExercise();
                _ctx.SaveChanges();
            }

            if (!_ctx.Classes.Any())
            {
                AddClasses();
                _ctx.SaveChanges();
            }

            if (!_ctx.Students.Any())
            {
                AddStudents();
                _ctx.SaveChanges();
            }

            if (!_ctx.Results.Any())
            {
                AddResults();
                _ctx.SaveChanges();
            }


            if (!_ctx.Persons.Any())
            {
//                 create sample data
                var filepath = Path.Combine(_hostingEnvironment.ContentRootPath, "Data/smt.json");
                var json     = File.ReadAllText(filepath);
//                var persons = JsonConvert.DeserializeObject<IEnumerable<ApplicationUser>>(json);
                _ctx.SaveChanges();
            }
        }
Beispiel #11
0
            public Result Handle(ChangeClassNumberCommand command)
            {
                var classes = _context.Classes.Where(x => !x.IsFinished);

                foreach (var schoolClass in classes)
                {
                    var classNumber = Helper.GetClassNumberFromClassName(schoolClass.Name);
                    if (classNumber == 12)
                    {
                        schoolClass.SetFinishedStatus(true);
                    }
                    else
                    {
                        var newClassNumber = classNumber + 1;
                        schoolClass.ChangeName(schoolClass.Name.Replace(classNumber.ToString(), newClassNumber.ToString()));
                        _context.Classes.Update(schoolClass);
                    }
                }

                _context.SaveChanges();
                return(Result.Ok());
            }
        public IActionResult AddResult(AddResultVm model)
        {
            if (!ModelState.IsValid)
            {
                return(View());
            }

            var aclass = _messages.Dispatch(new GetClassQuery(model.ClassId));

            if (aclass == null)
            {
                return(new NotFoundResult());
            }

            var exercise = _messages.Dispatch(new GetExerciseQuery(model.SelectedExerciseId));

            if (exercise == null)
            {
                return(new NotFoundResult());
            }

            var student = _messages.Dispatch(new GetStudentQuery(model.StudentId));

            if (student == null)
            {
                return(new NotFoundResult());
            }

            var result = new Result(student, exercise.Id, new ResultValue(exercise.Unit.Name, model.Result),
                                    DateTime.Now);

            _context.Results.Add(result);
            _context.SaveChanges();

            return(RedirectToAction("AddResult",
                                    new { selectedExerciseId = exercise.Id, selectedClassId = aclass.Id, gender = (int)student.Gender }));
        }