public IActionResult UpdateAccount(AccountHandlerJson accountHandler, int userId) { if (accountHandler.Sum == 0) { ViewBag.Id = accountHandler.AccountId; ViewBag.userId = userId; return(View()); } else { if (accountHandler.Operation == OperationJson.Decrease) { var user = _apiService.GetUser(userId).Result; if (user.Accounts.First(a => a.Id == accountHandler.AccountId).Score - accountHandler.Sum < 0) { return(Redirect("~/Home/Index")); } _apiService.PutAccount(accountHandler).Wait(); return(Redirect("~/Home/Index")); } else { _apiService.PutAccount(accountHandler).Wait(); return(Redirect("~/Home/Index")); } } }
public async Task PutAccount(AccountHandlerJson account) { HttpContent newAccountContent = new StringContent(JsonConvert.SerializeObject(account), Encoding.UTF8, "application/json"); response = await client.PutAsync("account/plus-or-minus-account", newAccountContent); }