public async Task <IActionResult> RegisterAsync([FromBody] CardRegistrationDto dto) { // check if card is already registered IdentityUser savedCard = await _cardManager.FindByIdAsync(dto.CardNumber); if (savedCard != null) { return(BadRequest("Card already registered")); } // check model is valid if (!ModelState.IsValid) { return(BadRequest(ModelState.Values)); } // use auto mapper to create IdentityCard from the dto var card = _mapper.Map <IdentityCard>(dto); IdentityResult identityResult = await _cardManager.CreateAsync(card, dto.Pin); if (identityResult.Succeeded) { return(Ok("Registered successfully")); } return(BadRequest(identityResult.Errors)); }