Beispiel #1
0
        public IActionResult Register(Account aAccountInfo)
        {
            aAccountInfo.Status = true;

            if (ModelState.IsValid)
            {
                bool        isSaveAccount      = _iAccountManager.Add(aAccountInfo);
                Account     lastAddAccountInfo = _iAccountManager.GetAll().LastOrDefault();
                RoleAccount initialRoleAccount = new RoleAccount()
                {
                    RoleId    = 2,
                    AccountId = lastAddAccountInfo.Id,
                    Status    = true
                };

                bool isSaveRoleAccount = _iRoleAccountManager.Add(initialRoleAccount);

                if (isSaveAccount == true && isSaveRoleAccount == true)
                {
                    return(RedirectToAction("Index", "Login"));
                }
                else
                {
                    ViewBag.ErrorMessage = "Registration has been failed! Try again.";
                    return(View(aAccountInfo));
                }
            }

            return(View(aAccountInfo));
        }
        public async Task <object> Register([FromBody] RegisterDto model)
        {
            var user = new IdentityUser
            {
                UserName = model.Email,
                Email    = model.Email
            };
            var result = await _userManager.CreateAsync(user, model.Password);

            if (result.Succeeded)
            {
                try
                {
                    _accountManager.Add(model);
                }
                catch (Exception e)
                {
                    return(Conflict(e.Message));
                }
                await _signInManager.SignInAsync(user, false);

                var roleResult = await _userManager.AddToRoleAsync(user, "User");

                return(Ok("Success!!"));
            }
            else
            {
                return(Conflict(result.Errors));
            }
        }
Beispiel #3
0
        public IHttpActionResult Post([FromBody] RegisterBindingModel registerModel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var account = _accountManager.FindAccountByEmail(registerModel.Email);

            if (account != null)
            {
                return(Conflict());
            }

            account = _accountManager.Add(registerModel);

            var accountDTO = new AccountDTO()
            {
                id    = account._id,
                name  = account.name,
                email = account.email
            };

            return(Ok(accountDTO));
        }
        public IActionResult Create(Account aAccount)
        {
            if (ModelState.IsValid)
            {
                bool isAdd = _iAcccountManager.Add(aAccount);

                if (isAdd)
                {
                    return(RedirectToAction("Index"));
                }
                else
                {
                    return(ViewBag.ErrorMessage = "Account create has been failed!");
                }
            }

            ViewBag.BranchList        = BranchList();
            ViewBag.AccountTypeList   = AccountTypeList();
            ViewBag.AccountStatusList = AccountStatusList();
            return(View(aAccount));
        }