示例#1
0
        public async Task <Result> CreateDeveloperAsync(DeveloperCreateDto developerDto)
        {
            var existLogin = await _developerRepository.ExistByLoginAsync(developerDto.Login);

            if (existLogin)
            {
                return(new Result(Status.Conflict, $"Developer with {nameof(developerDto.Login)} already exist"));
            }
            var validCpf = await _mockyService.ValidateCPFAsync(developerDto.CPF);

            if (!validCpf.Success)
            {
                return(new Result(validCpf.Status, validCpf.ErrorMessages));
            }
            if (!validCpf.Data)
            {
                return(new Result(Status.Invalid, $"Parameter {nameof(developerDto.CPF)} is not valid"));
            }

            var developer = new Developer(
                id: developerDto.Id,
                name: developerDto.Name,
                login: developerDto.Login,
                cpf: developerDto.CPF,
                password: developerDto.Password
                );

            await _developerRepository.CreateAsync(developer);

            return(new Result());
        }
示例#2
0
        public async Task <IActionResult> Register(RegisterViewModel registerVM, string returnUrl = null)
        {
            ViewData["ReturnUrl"] = returnUrl;
            if (ModelState.IsValid)
            {
                _logger.LogInformation("********Role: " + registerVM.Role + "*************");

                //IdentityResult result = null;

                //var user = registerVM.Role == Roles.DOCTOR ? (ApplicationUser) doctor : (ApplicationUser) patient;
                switch (registerVM.Role)
                {
                case Roles.DOCTOR:
                    Doctor doctor = registerVM.GetNewDoctor();
                    doctor = await _doctorRepository.CreateAsync(doctor);

                    await _userManager.AddToRoleAsync(doctor, Roles.DOCTOR.ToUpper());

                    //await _users.AssignRole(doctor.UserName, Roles.DOCTOR.ToUpper());
                    await SetupUser(doctor, registerVM);

                    break;

                case Roles.PATIENT:
                    Patient patient = await registerVM.GetNewPatient(_doctorRepository);

                    patient = await _patientRepository.CreateAsync(patient);

                    await _userManager.AddToRoleAsync(patient, Roles.PATIENT);
                    await SetupUser(patient, registerVM);

                    break;

                case Roles.DEVELOPER:
                    Developer dev = registerVM.GetNewDeveloper();
                    //var result = await _userManager.CreateAsync(dev, registerVM.Password);
                    dev = await _developerRepository.CreateAsync(dev);

                    await _userManager.AddToRoleAsync(dev, Roles.DEVELOPER);
                    await SetupUser(dev, registerVM);

                    break;

                default:
                    break;
                }

                //var user = new ApplicationUser { UserName = registerVM.Email, Email = registerVM.Email };

                //if ( result != null && result.Succeeded )
                //{
                return(RedirectToLocal(returnUrl));

                //} // if

                //AddErrors( result );
            } // if

            // If we got this far, something failed, redisplay form
            return(View(registerVM));
        } // Register