public async Task <ActionResult <AccountDto> > CreateAccount([FromBody] RegisterDto register) { if (_accountService.AccountExists(register.Username)) { return(null); } User user = new User(); user = _mapper.Map <User>(register); _userService.CreateUser(user); Account account = _accountService.Register(user.Id, register); var claimName = new Claim(ClaimTypes.Name, account.Username); var claimAccount = new Claim("AccountId", account.Id); var clamUser = new Claim("UserId", account.UserId); var claimsIdentity = new ClaimsIdentity(new[] { claimName, claimAccount, clamUser }, "serverAuth"); //create claimsPrincipal var claimsPrincipal = new ClaimsPrincipal(claimsIdentity); //Sign In User await HttpContext.SignInAsync(claimsPrincipal); return(await Task.FromResult(_mapper.Map <AccountDto>(account))); }
public async Task <IActionResult> Edit(int id, [Bind("ID,Name,Email,Password,Username,RoleId,UserRole,CreateAt,UpdateAt")] Account account) { if (id != account.ID) { return(NotFound()); } if (ModelState.IsValid) { try { //_context.Update(account); //wait _context.SaveChangesAsync(); accountService.UpdateAccount(account); } catch (DbUpdateConcurrencyException) { if (!accountService.AccountExists(account.ID)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(account)); }
public void TestAccountExistsReturnsFalseIfAccountDoesNotExist() { var mirrorRepository = new Mirror<IAccountRepository>(); var accountService = new AccountService(mirrorRepository.It); Assert.IsFalse(accountService.AccountExists(456)); }
public void TestAccountExistsReturnsTrueIfAccountExists() { var mirrorRepository = new Mirror<IAccountRepository>(); mirrorRepository.Returns(r => r.GetAccount(123), new Account()); var accountService = new AccountService(mirrorRepository.It); Assert.IsTrue(accountService.AccountExists(123)); }
public void AccountExists_ReturnsTrueIfAccountExists() { Assert.IsTrue(service.AccountExists(accountId)); }