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

            if (ModelState.IsValid)
            {
                try
                {
                    _contexto.Update(bebida);
                    await _contexto.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!BebidaExists(bebida.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(bebida));
        }
示例#2
0
        public async Task UpdateAsync(Pedido obj)
        {
            bool hasAny = await _contexto.Prato.AnyAsync(x => x.Id == obj.Id);

            if (!hasAny)
            {
                throw new Exception("Id not found");
            }
            try
            {
                _contexto.Update(obj);
                await _contexto.SaveChangesAsync();
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
        }