public async Task <IActionResult> Edit(int id, [Bind("ID,Nome")] TipoCusto tipoCusto)
        {
            if (id != tipoCusto.ID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(tipoCusto);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!TipoCustoExists(tipoCusto.ID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(tipoCusto));
        }
        public async Task <IActionResult> Create([Bind("ID,Nome")] TipoCusto tipoCusto)
        {
            if (ModelState.IsValid)
            {
                _context.Add(tipoCusto);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(tipoCusto));
        }
Пример #3
0
        public IActionResult Post([FromBody] TipoCusto tipoCusto)
        {
            try
            {
                _tipoCustoRepository.Adicionar(tipoCusto);

                return(Created("api/TipoCusto", tipoCusto));
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.ToString()));
            }
        }