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

            var userIdentity = _mapper.Map <User>(model);

            var result = await _userManager.CreateAsync(userIdentity, model.Password);

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

            await _dbContext.Customers.AddAsync(new Customer
            {
                IdentityId = userIdentity.Id,
                Location   = model.Location
            });

            await _dbContext.SaveChangesAsync();

            return(new OkObjectResult("Account created"));
        }