Beispiel #1
0
        public async Task <ActionResult> Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = new ApplicationUser {
                    UserName = model.Email, Email = model.Email
                };
                IdentityResult result = await UserManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    UserManager.AddClaim(user.Id, new Claim(ClaimTypes.GivenName, model.FirstName));
                    var service = new PatientAccountService(HttpContext.GetOwinContext().Get <ApplicationDbContext>());
                    service.CreatePatient(model.FirstName, model.LastName, user.Id, 0);
                    await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false);

                    // For more information on how to enable account confirmation and password reset please visit https://go.microsoft.com/fwlink/?LinkID=320771
                    // Send an email with this link
                    // string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);
                    // var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
                    // await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>");

                    return(RedirectToAction("Index", "Home"));
                }
                AddErrors(result);
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
        protected override void ConfigureWebHost(IWebHostBuilder builder)
        {
            builder.ConfigureTestServices(services =>
            {
                Mock <IRegistrationNotifier> registrationNotifier = new Mock <IRegistrationNotifier>();
                string connectionString      = CreateConnectionStringFromEnvironment();
                var patientAccountRepository = new PatientAccountSqlRepository(new UserSqlTestContextFactory(connectionString));

                var patientAccountService      = new PatientAccountService(patientAccountRepository);
                var patientRegistrationService = new PatientRegistrationService(patientAccountService, registrationNotifier.Object);

                services.Add(new ServiceDescriptor(typeof(IPatientRegistrationService), patientRegistrationService));
            });
        }
        private void AddServices(IServiceCollection services)
        {
            var cityRepository = new CitySqlRepository(GetContextFactory());
            var cityService    = new CityService(cityRepository);

            services.Add(new ServiceDescriptor(typeof(CityService), cityService));

            var countryRepository = new CountrySqlRepository(GetContextFactory());
            var countryService    = new CountryService(countryRepository);

            services.Add(new ServiceDescriptor(typeof(CountryService), countryService));

            var doctorRepositry = new DoctorSqlRepository(GetContextFactory());
            var doctorService   = new DoctorService(doctorRepositry);

            services.Add(new ServiceDescriptor(typeof(DoctorService), doctorService));

            var patientRepository        = new PatientSqlRepository(GetContextFactory());
            var patientAccountRepository = new PatientAccountSqlRepository(GetContextFactory());
            var registrationNotifier     = new RegistrationNotifier(
                "http://" +
                Environment.GetEnvironmentVariable("PSW_API_GATEWAY_HOST") +
                ":" +
                Environment.GetEnvironmentVariable("PSW_API_GATEWAY_PORT") +
                "/api/patient/activate/");

            var patientAccountService      = new PatientAccountService(patientAccountRepository);
            var patientRegistrationService = new PatientRegistrationService(patientAccountService, registrationNotifier);

            var patientService = new PatientService(patientRepository, patientAccountRepository);

            var specialtyRepository = new SpecialtySqlRepository(GetContextFactory());
            var specialtyService    = new SpecialtyService(specialtyRepository);

            // Auth
            var userAccountRepository = new UserAccountSqlRepository(GetContextFactory());
            var credentialService     = new CredentialsService(userAccountRepository, GetJwtSecretFromEnvironment());

            // Advertisement
            var advertisementRepository = new AdvertisementSqlRepository(GetContextFactory());
            var advertisementService    = new AdvertisementService(advertisementRepository);

            services.Add(new ServiceDescriptor(typeof(CredentialsService), credentialService));
            services.Add(new ServiceDescriptor(typeof(IPatientAccountService), patientAccountService));
            services.Add(new ServiceDescriptor(typeof(IPatientRegistrationService), patientRegistrationService));
            services.Add(new ServiceDescriptor(typeof(PatientService), patientService));
            services.Add(new ServiceDescriptor(typeof(SpecialtyService), specialtyService));
            services.Add(new ServiceDescriptor(typeof(AdvertisementService), advertisementService));
        }