public async Task <IActionResult> SpojAccountCenter([Bind("Username,Password,ConfirmPassword")] SpojAccountModel model) { model.UserId = _userManager.GetUserId(User); await _userService.UpdateUserSpojAccountAsync(model); //var response = await _userService.GetCurrentUserSpojAccount(User); return(RedirectToAction("Index", "Home")); }
public async Task UpdateUSerSpojAccountAsyncAsync(SpojAccountModel model) { if (model.Password != model.ConfirmPassword) { throw new SpojDebugException("Password and confirm password must equal"); } var account = _accountRepository.Get(x => x.UserName == model.Username).FirstOrDefault(); if (account == null) { throw new SpojDebugException("Spoj Account has not existed in system"); } if (account.UserId != null && account.UserId != model.UserId) { throw new SpojDebugException("Sorry. This Spoj account was used by another user"); } using (var client = new SpojClient()) { await client.LoginAsync(model.Username, model.Password); var isLogin = await client.IsLoginSuccess(); if (!isLogin) { throw new SpojDebugException("Sorry. We can not authorized this Spoj account for you. Make sure that you can login this account into Spoj.com"); } account.UserId = model.UserId; var oldAccounts = _accountRepository.Get(x => x.UserId == model.UserId); foreach (var acc in oldAccounts.ToList()) { acc.UserId = null; _accountRepository.Update(acc, x => x.UserId); } _accountRepository.Update(account, x => x.UserId); _accountRepository.SaveChanges(); } }
public async Task UpdateUserSpojAccountAsync(SpojAccountModel model) { await _userBusiness.UpdateUSerSpojAccountAsyncAsync(model); }