Exemplo n.º 1
0
        public IActionResult Edit(long id, ExpenseDto expense)
        {
            if (id != expense.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _service.Update(expense);
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ExpenseExists(expense.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(expense));
        }
        public void UpdateAllNames()
        {
            // arrange
            var all = _appService.Get().ToList();

            for (int i = 0; i < all.Count; i++)
            {
                all[i].Name = string.Format(Resource.NewName, i);
            }

            // act
            all.ForEach(x => _appService.Update(x));

            // act
            for (int i = 0; i < _appService.Get().ToList().Count; i++)
            {
                Assert.AreEqual(string.Format(Resource.NewName, i), all[i].Name);
            }
        }
        public ActionResult Save(ExpenseViewModel expense)
        {
            var expenseModel = expense.To <Expense>();

            if (ModelState.IsValid)
            {
                if (expenseModel.Id != default(Guid))
                {
                    _expenseApp.Update(expenseModel);
                }
                else
                {
                    _expenseApp.Add(expenseModel);
                }
            }

            return(Json(expenseModel, JsonRequestBehavior.AllowGet));
        }