Esempio n. 1
0
        public async Task UpdateAccountAsync(int accountId, AccountForUpdatingDto account)
        {
            string reqUrl = baseUrl + accountId;

            var client = _clientFactory.CreateClient();

            HttpResponseMessage response = await client.PutAsJsonAsync(reqUrl, account);

            response.EnsureSuccessStatusCode();
        }
        public async Task <IActionResult> Edit(int id, [FromForm] AccountForUpdatingDto update)
        {
            if (id != update.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                await _svc.UpdateAccountAsync(id, update);


                return(RedirectToAction("Index"));
            }

            return(View(update));
        }
        public async Task <IActionResult> Edit(int id)
        {
            var account = await _svc.GetAccountAsync(id, false);

            if (account == null)
            {
                return(NotFound());
            }

            var editedAccount = new AccountForUpdatingDto()
            {
                Id          = account.Id,
                Name        = account.Name,
                Description = account.Description
            };

            return(View(editedAccount));
        }
Esempio n. 4
0
        public IActionResult UpdateAccount(int id,
                                           [FromBody] AccountForUpdatingDto editedAccount)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (!_accountRepo.AccountExists(id))
            {
                return(NotFound());
            }

            Account accountFromStore = _accountRepo.GetAccount(id, false);

            accountFromStore.Id          = editedAccount.Id;
            accountFromStore.Name        = editedAccount.Name;
            accountFromStore.Description = editedAccount.Description;

            if (!_accountRepo.Save())
            {
                return(StatusCode(500, "A problem happened while handling your request"));
            }

            return(NoContent());

            //var accountFromStore = AccountsDataStore.Current.Accounts
            //    .FirstOrDefault(a => a.Id == id);
            //if (accountFromStore == null)
            //{
            //    return NotFound();
            //}
            //if (!ModelState.IsValid)
            //{
            //    return BadRequest(ModelState);
            //}

            //accountFromStore.Name = editedAccount.Name;
            //accountFromStore.Description = editedAccount.Description;

            //return NoContent();
        }