Exemple #1
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,BalanceId,Category,Description,Amount,Date")] Spending spending)
        {
            if (id != spending.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    if (await _repository.Update(spending) != null)
                    {
                        return(RedirectToAction(nameof(Details), "Balance", new { id = spending.BalanceId }, null));
                    }
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!_repository.SpendingExists(spending.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(spending));
        }
Exemple #2
0
        public async Task <IActionResult> PutSpending(int id, Spending spending)
        {
            try
            {
                if (id != spending.Id)
                {
                    return(BadRequest());
                }

                if (await _repository.Update(spending) == null)
                {
                    return(BadRequest());
                }

                await _repository.UpdateBalance(spending.BalanceId);

                return(NoContent());
            }
            catch (Exception)
            {
                if (!_repository.Exist(id))
                {
                    return(NotFound());
                }
                else
                {
                    return(BadRequest());
                }
            }
        }
Exemple #3
0
        public void Update_Test()
        {
            item.Id           = 1;
            item.Description  = "bla bla";
            item.SpendingDate = DateTime.Now;
            item.MoneySpent   = 5;

            item.MoneySpent = 7;

            spendingRepo.Update(item);
        }