Exemple #1
0
        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)));
        }
Exemple #2
0
        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));
        }
Exemple #3
0
        public void TestAccountExistsReturnsFalseIfAccountDoesNotExist()
        {
            var mirrorRepository = new Mirror<IAccountRepository>();
            var accountService = new AccountService(mirrorRepository.It);

            Assert.IsFalse(accountService.AccountExists(456));
        }
Exemple #4
0
        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));
        }
Exemple #5
0
 public void AccountExists_ReturnsTrueIfAccountExists()
 {
     Assert.IsTrue(service.AccountExists(accountId));
 }