Пример #1
0
            public bool Handle(ArchiveLectureCommand command)
            {
                var lecture = _dbContext.Lectures.Find(command.Id);

                if (lecture == null)
                {
                    return(false);
                }
                if (lecture.CanArchive())
                {
                    lecture.ArchiveLecture();
                    _dbContext.SaveChanges();
                    return(true);
                }
                return(false);
            }
Пример #2
0
            //todo: kui me tahame midagi kasutajale tagastada siis kontroll controlleri
            // kui on mingi põhjus et me ei saa valideerimist teha domeenis siis paneme Commandi
            //
            public bool Handle(CloseLectureCommand command)
            {
                var lecture = _dbContext.Lectures.Find(command.Id);

                if (lecture == null)
                {
                    return(false);
                }

                if (lecture.Status == LectureStatus.Open)
                {
                    lecture.CloseLecture();
                    _dbContext.SaveChanges();
                    return(true);
                }
                return(false);
            }
Пример #3
0
            public bool Handle(EnrollStudentCommand command)
            {
                // todo teoorias võiks spec olla ( vb peaks queryt täiendama, et saaks include lisada )
                var lecture = _context.Lectures.Where(l => l.Id == command.LectureId).Include(x => x.Enrollments).FirstOrDefault();
                var student = _context.Students.FirstOrDefault(s => s.Name == command.StudentName); // getStudentsWithNameSpec

                if (lecture == null && student == null)
                {
                    return(false);
                }

                if (lecture.CanEnroll(student))
                {
                    lecture.EnrollStudent(student.Id);
                    _context.SaveChanges();
                    return(true);
                }

                return(false);
            }