//GET public async Task <IActionResult> Edit(int id) { EditBankAccountViewModel viewModel = await _currencyViewModelSerivce.GetBankAccountViewModel(id : id); ViewBag.Currencies = viewModel.SelectCurrencyList; CurrencyConvertModel currencyConvertModel = viewModel.ConvertModel; return(View(model: currencyConvertModel)); }
public ActionResult Edit(EditBankAccountViewModel model) { if (ModelState.IsValid) { var account = _manager.Get(model.Id); account.Name = model.Name; _manager.Edit(account); } return(RedirectToAction("Index")); }
public PartialViewResult EditBankAccountModal(int id) { var account = _manager.Get(id); var model = new EditBankAccountViewModel() { Name = account.Name }; return(PartialView(model)); }
public async Task <IActionResult> Create([Bind("Id,Name,BankAccountType")] EditBankAccountViewModel bankAccountViewModel) { var bankAccount = new BankAccount { Name = bankAccountViewModel.Name, BankAccountType = bankAccountViewModel.BankAccountType, User = await GetCurrentUser() }; if (ModelState.IsValid) { _context.Add(bankAccount); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(bankAccountViewModel)); }
public ActionResult Edit(int?id) { if (id != null) { if (db.BankAccounts.Find(id) != null) { var account = db.BankAccounts.Find(id); var vm = new EditBankAccountViewModel( db.BankNames.ToList(), db.BankAccountTypes.ToList(), account.BankNameId, account.BankAccountTypeId ); vm.NickName = account.NickName; ViewBag.Id = account.Id; return(View(vm)); } } return(RedirectToAction("Index", "Home")); }
public ActionResult Edit(EditBankAccountViewModel model) { if (ModelState.IsValid) { BankAccount ba = _repo.GetBankAccount(model.AccountNumber); ba.Frozen = model.Frozen; ba.AccountNumber = model.AccountNumber; ba.Balance = model.Balance; ba.DebitLimit = model.DebitLimit; ba.Locks = model.Locks; _repo.Update(ba); _repo.Save(); TempData["message"] = string.Format("Konto bankowe zostało zedytowane!"); return(RedirectToAction("Index")); } ModelState.AddModelError("", "Błąd"); return(View(model)); }
public ActionResult EditBankAccount(int id, EditBankAccountViewModel formData) { if (!ModelState.IsValid) { return(View(formData)); } var httpClient = new HttpClient(); httpClient.DefaultRequestHeaders.Add("Authorization", $"Bearer {ViewBag.Token}"); var parameters = new List <KeyValuePair <string, string> >(); parameters.Add(new KeyValuePair <string, string>("Name", formData.Name)); parameters.Add(new KeyValuePair <string, string>("Description", formData.Description)); var enCodeParameters = new FormUrlEncodedContent(parameters); var url = $"http://localhost:55336/api/BankAccount/Update/{id}"; var response = httpClient.PutAsync(url, enCodeParameters).Result; if (response.StatusCode == System.Net.HttpStatusCode.OK) { TempData["Message"] = "BankAccount was edited successfully"; return(RedirectToAction("ListOfBankAccount", "BankAccount", new { id = formData.HouseHoldId })); } else if (response.StatusCode == System.Net.HttpStatusCode.BadRequest) { var data = response.Content.ReadAsStringAsync().Result; var result = JsonConvert.DeserializeObject <APIErrorData>(data); foreach (var ele in result.ModelState) { ModelState.AddModelError("", ele.Value[0].ToString()); } return(View(formData)); } else { return(RedirectToAction("Error", "Home")); } }
public ActionResult Edit(EditBankAccountViewModel vm, int?id) { if (id != null) { if (!ModelState.IsValid) { vm.BankAccountTypeList = new SelectList(db.BankAccountTypes.ToList(), "Id", "Name", vm.BankAccountTypeSelection); vm.BankNameList = new SelectList(db.BankNames.ToList(), "Id", "Name", vm.BankNameSelection); return(View(vm)); } var account = db.BankAccounts.Find(id); if (account != null) { account.NickName = vm.NickName; account.BankNameId = vm.BankNameSelection; account.BankAccountTypeId = vm.BankAccountTypeSelection; db.Entry(account).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index", "Home")); } } return(RedirectToAction("Index", "Home")); }
/// <summary> /// Отображаем Edit /// </summary> /// <param name="id">Аккаунт для которого формируем VM</param> /// <returns></returns> public async Task <EditBankAccountViewModel> GetBankAccountViewModel(int id) { //Получаем Акк BankAccount account = await _bankAccountRepository.GetById(id : id); List <Currency> currencies = await _currencyRepository.GetAll(); var viewModel = new EditBankAccountViewModel { //Список с валютами SelectCurrencyList = new SelectList(items: currencies, dataValueField: "Id", dataTextField: "ShortName"), //Модель данных формы ConvertModel = new CurrencyConvertModel { From = account.IdCurrencyNavigation.ShortName, FromId = account.IdCurrency, Amount = account.Amount } }; return(viewModel); }
// GET: BankAccounts/Edit/5 public async Task <IActionResult> Edit(long?id) { if (id == null) { return(NotFound()); } var bankAccount = await GetBankAccount(id.Value); if (bankAccount == null) { return(NotFound()); } var bankAccountViewModel = new EditBankAccountViewModel { Id = bankAccount.Id, Name = bankAccount.Name, BankAccountType = bankAccount.BankAccountType, }; return(View(bankAccountViewModel)); }
public ActionResult Edit(Guid id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } BankAccount ba = _repo.GetBankAccount(id); if (ba == null) { return(HttpNotFound()); } EditBankAccountViewModel model = new EditBankAccountViewModel() { AccountNumber = ba.AccountNumber, Balance = ba.Balance, DebitLimit = ba.DebitLimit, Frozen = ba.Frozen, Locks = ba.Locks }; return(View(model)); }
public ActionResult Edit(EditBankAccountViewModel bankAccountViewModel) { if (!ModelState.IsValid) { return(View(bankAccountViewModel)); } var url = $"{ProjectConstants.APIURL}/api/bankaccount/edit/{bankAccountViewModel.Id}"; var parameters = new List <KeyValuePair <string, string> > { new KeyValuePair <string, string>("Name", bankAccountViewModel.Name), new KeyValuePair <string, string>("Description", bankAccountViewModel.Description) }; var encodedParameters = new FormUrlEncodedContent(parameters); var response = HttpClientContext.httpClient.PostAsync(url, encodedParameters).Result; if (response.IsSuccessStatusCode) { TempData.Add("Message", $"Account '{bankAccountViewModel.Name}' Edited!"); return(RedirectToAction("HouseholdBankAccounts", "BankAccount", new { Id = bankAccountViewModel.HouseholdId })); } else { ErrorHelpers.HandleResponseErrors(response, TempData, ModelState); if (bankAccountViewModel != null) { return(View(bankAccountViewModel)); } else { return(RedirectToAction("Index", "Household")); } } }
public async Task <IActionResult> Edit(long id, [Bind("Id,Name,BankAccountType")] EditBankAccountViewModel bankAccountViewModel) { if (id != bankAccountViewModel.Id) { return(NotFound()); } var bankAccount = new BankAccount { Id = bankAccountViewModel.Id, Name = bankAccountViewModel.Name, BankAccountType = bankAccountViewModel.BankAccountType, User = await GetCurrentUser() }; if (ModelState.IsValid) { try { _context.Update(bankAccount); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!BankAccountExists(bankAccount.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(bankAccountViewModel)); }
/// <summary> /// Отображаем Edit /// </summary> /// <param name="id">Аккаунт для которого формируем VM</param> /// <returns></returns> public async Task <EditBankAccountViewModel> GetBankAccountViewModel(int id) { //Получаем Акк var account = await _bankAccountRepository.GetById(id); var currencies = await _currencyRepository.GetAll(); var idCurrency = account.IdCurrency; var find = currencies.Find(currency => currency.IdCurrency.Equals(idCurrency)); currencies.Remove(find); var viewModel = new EditBankAccountViewModel { //Список с валютами CurrencyList = currencies, CurrentCurrencyId = account.IdCurrency, CurrentCurrencyName = account.IdCurrencyNavigation.ShortName, CurrentAmount = account.Amount, IdAccount = account.IdAccount, }; return(viewModel); }
public ActionResult Edit(int?id) { var cookie = Request.Cookies["MyCookie"]; if (cookie == null) { return(RedirectToAction("Login", "Account")); } var httpClient = new HttpClient(); httpClient.DefaultRequestHeaders.Add("Authorization", $"Bearer {cookie.Value}"); string url = $"http://localhost:64310/api/BankAccount/GetBankAccount/{id}"; var response = httpClient .GetAsync(url) .Result; if (response.StatusCode == System.Net.HttpStatusCode.OK) { var data = response.Content.ReadAsStringAsync().Result; var result = JsonConvert.DeserializeObject <BankAccountViewModel>(data); var editViewModel = new EditBankAccountViewModel(); editViewModel.Name = result.Name; editViewModel.Description = result.Description; ViewBag.id = id; return(View(editViewModel)); } else { return(View("Error")); } }
public ActionResult Edit(int?id, EditBankAccountViewModel model) { var cookie = Request.Cookies["MyCookie"]; if (cookie == null) { return(RedirectToAction("Login", "Account")); } if (!ModelState.IsValid) { return(View(model)); } var parameters = new List <KeyValuePair <string, string> >(); parameters.Add( new KeyValuePair <string, string>("Name", model.Name)); parameters.Add( new KeyValuePair <string, string>("Description", model.Description)); var encodedParameters = new FormUrlEncodedContent(parameters); var httpClient = new HttpClient(); httpClient.DefaultRequestHeaders.Add("Authorization", $"Bearer {cookie.Value}"); var response = httpClient .PostAsync($"http://localhost:64310/api/BankAccount/Edit/{id}", encodedParameters) .Result; if (response.StatusCode == System.Net.HttpStatusCode.OK) { return(RedirectToAction("Household", "Home")); } else if (response.StatusCode == System.Net.HttpStatusCode.BadRequest) { var data = response.Content.ReadAsStringAsync().Result; var errors = JsonConvert.DeserializeObject <BudgetCalculatorFrontEnd.Models.Domain.Error>(data); foreach (var key in errors.ModelState) { foreach (var error in key.Value) { ModelState.AddModelError(key.Key, error); } } ViewBag.id = id; return(View("Error")); } else if (response.StatusCode == System.Net.HttpStatusCode.NotFound) { return(RedirectToAction("Index", "Home")); } else { //Create a log for the error message ModelState.AddModelError("", "Sorry. An unexpected error has occured. Please try again later"); return(View(model)); } }