Example #1
0
            public async Task <int> Handle(Command request, CancellationToken cancellationToken)
            {
                var student = new Student
                {
                    StudentId   = request.student_id,
                    StudentName = request.student_name,
                    Dependency  = request.dependency,
                    PhoneNumber = request.phone_number,
                    Email       = request.email,
                    AccountType = AccountType.FromValue(request.typeOfAccount),
                    Password    = request.password
                };

                if (_db.Students.Any(x => x.StudentId == request.student_id))
                {
                    throw new Exception("La matrícula ya está en uso.");
                }

                if (_db.Students.Any(x => x.Email == student.Email))
                {
                    throw new Exception("El correo ya está en uso.");
                }

                if (!request.email.EndsWith("uanl.edu.mx"))
                {
                    throw new Exception("El correo debe ser oficial de la UANL.");
                }

                _db.Students.Add(student);
                await _db.SaveChangesAsync();

                return(student.StudentId);
            }