Beispiel #1
0
        public IActionResult CreaeteUserAccount([FromBody] CreateAccountRequest accUserRequest)
        {
            if (Exited(accUserRequest.Email))
            {
                return(StatusCode(400, new { message = "Account already existed" }));
            }

            var account = _mapper.Map <Account>(accUserRequest);

            account.Password = Encode(account.Password);
            _accountservice.Create(account);

            CreateRoleForAccount(account.Email, "user");

            var  accountget = _accountservice.Get(a => a.Email.Equals(account.Email), null);
            User user       = new User();

            user.AccountId = accountget.Id;
            _userService.Create(user);

            var roleid         = _accountroleservice.Get(a => a.AccountId == accountget.Id, null).RoleId;
            var role           = _roleservice.Get(a => a.Id == roleid, null).Name;
            var accountreponse = _mapper.Map <AccountResponse>(accountget);

            accountreponse.Role.Add(role);
            string tokenStr = GenerateJSONWebToken(accountreponse);

            return(StatusCode(200, new { token = tokenStr, id = accountget.Id, role = accountreponse.Role }));
        }
Beispiel #2
0
        public IActionResult UpdateAccount(int id)
        {
            var userrole = _accountRoleService.Get(a => a.AccountId == id, null);

            userrole.RoleId = _roleService.Get(a => a.Name.Equals("customer"), null).Id;

            _accountRoleService.Update(userrole);
            return(StatusCode(200, new { message = "Update Success" }));
        }