public IActionResult Register(RegisterRequest request)
        {
            Address[] addresses = request.Addresses
                                  .Select(x => Address.Create(x.Street, x.City, x.State, x.ZipCode, _stateRepository.GetAll()).Value)
                                  .ToArray();

            Email  email = Email.Create(request.Email).Value;
            string name  = request.Name.Trim();

            Student existingStudent = _studentRepository.GetByEmail(email);

            if (existingStudent != null)
            {
                return(Error(Errors.Student.EmailIsTaken()));
            }

            var student = new Student(email, name, addresses);

            _studentRepository.Save(student);

            var response = new RegisterResponse
            {
                Id = student.Id
            };

            return(Ok(response));
        }
Пример #2
0
        public IActionResult Register(StudentDto request)
        {
            var addresses = request.Addresses.Select(a => new Address(a.Street, a.City, a.State, a.ZipCode)).ToList();

            Result <Email, Error> email = Email.Create(request.Email);
            Result <StudentName>  name  = StudentName.Create(request.Name);

            if (email.IsFailure)
            {
                return(BadRequest(email.Error));
            }
            if (name.IsFailure)
            {
                return(BadRequest(name.Error));
            }

            var student = new Student(email.Value, name.Value, request.Phone, addresses);

            _studentRepository.Save(student);

            var response = new RegisterResponse
            {
                Id = student.Id
            };

            return(Ok(response));
        }
Пример #3
0
        public IActionResult Register([FromBody] RegisterRequest request)
        {
            var student = new Student(request.Email, request.Name, request.Address);

            _studentRepository.Save(student);

            var resonse = new RegisterResonse
            {
                Id = student.Id
            };

            return(Ok(resonse));
        }