示例#1
0
        public async Task <ServiceResult> RegisterMuseumAsync(MuseumRegistrationModel model)
        {
            var museum = new Museum
            {
                Name = model.MuseumName,
            };

            await museumRepository.CreateAsync(museum);

            var user = new ApplicationUser
            {
                UserName = model.Username,
                Email    = model.Email,
                Museum   = museum,
            };

            var identityResult = await userManager.CreateAsync(user, model.Password);

            if (identityResult.Succeeded)
            {
                await emailConfirmationService.SendConfirmationEmailAsync(user, "");

                return(ServiceResult <ApplicationUser> .Success(user));
            }

            var serviceErrors = identityResult.Errors.Select(error => new ServiceError {
                Code = error.Code, Description = error.Description
            });

            return(ServiceResult.Failed(serviceErrors.ToArray()));
        }
        public async Task <IActionResult> RegisterMuseum(RegistrationViewModel model)
        {
            var registrationModel = new MuseumRegistrationModel
            {
                Email      = model.Email,
                MuseumName = model.MuseumName,
                Password   = model.Password,
                Username   = model.Username,
            };
            var result = await museumRegistrationService.RegisterMuseumAsync(registrationModel);

            if (result.Succeeded)
            {
                var user = await userManager.FindByEmailAsync(model.Email);

                var code = await userManager.GenerateEmailConfirmationTokenAsync(user);

                var callbackUrl = Url.Action(
                    "ConfirmEmail",
                    "Registration",
                    new { userId = user.Id, code = code },
                    Request.Scheme);
                await emailConfirmationService.SendConfirmationEmailAsync(user, callbackUrl);

                return(Ok());
            }
            ;
            return(BadRequest(result));
        }