Exemplo n.º 1
0
        public async Task <SignUpViewModel> SignUp(SignUpInputModel signUpInputModel)
        {
            bool   isOng   = signUpInputModel.Document.Length > 11;
            string profile = isOng ? UserProfileEnum.ONG.ToString() : UserProfileEnum.VOLUNTARY.ToString();

            int personId = await _personRepository.AddPerson(new Person(signUpInputModel.Name, signUpInputModel.Phone));

            if (personId > 0)
            {
                if (isOng)
                {
                    await _personRepository.AddLegalPerson(new LegalPerson(signUpInputModel.Document, personId));

                    await _ongRepository.Add(new Ong(null, null, string.Empty, string.Empty, personId));
                }
                else
                {
                    await _personRepository.AddPhysicalPerson(new PhysicalPerson(signUpInputModel.Document, personId));
                }
            }

            int userId = await _userRepository.Add(new User(signUpInputModel.Password, profile, signUpInputModel.Facebook_Unique_id, signUpInputModel.Email, personId));

            return(new SignUpViewModel(userId > 0));
        }