示例#1
0
        public async Task <IActionResult> Post([FromBody] RegistrationViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var userIdentity = _mapper.Map <AppUser>(model);
            var result       = await _userManager.CreateAsync(userIdentity, model.Password);

            if (!result.Succeeded)
            {
                return(new BadRequestObjectResult(Errors.AddErrorsToModelState(result, ModelState)));
            }

            await _appDbContext.UserInfo.AddAsync(new UserInfo
            {
                IdentityId  = userIdentity.Id,
                Location    = model.Location,
                Gender      = model.Gender,
                ColorTheme  = model.ColorTheme,
                ProfileName = model.ProfileName,
                Email       = model.Email
            }
                                                  );

            await _appDbContext.SaveChangesAsync();

            var newUser = await _appDbContext.UserInfo.FirstOrDefaultAsync(e => e.IdentityId == userIdentity.Id);

            var resposnse = _mapper.Map <UserInfo, UserProfileResponse>(newUser);

            return(Ok(resposnse));
        }
示例#2
0
 public async Task CompleteAsync()
 {
     await _context.SaveChangesAsync();
 }