public async Task <IActionResult> PutEvento([FromRoute] int id, [FromBody] Evento evento)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != evento.id)
            {
                return(BadRequest());
            }

            _context.Entry(evento).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!EventoExiste(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Example #2
0
        public async Task <ActionResult <Evento> > PostEvento(Evento evento)
        {
            _context.Eventos.Add(evento);
            SetStatusEvento(evento);

            await _context.SaveChangesAsync();

            return(CreatedAtAction(nameof(GetEvento), new { id = evento.Id }, evento));
        }
Example #3
0
        public async Task <IActionResult> Create([Bind("Id,Nome,Valor,Gratuito,Descricao,Data")] Evento evento)
        {
            if (ModelState.IsValid)
            {
                evento.Id = Guid.NewGuid();
                _context.Add(evento);

                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }

            return(View(evento));
        }
Example #4
0
 public async Task <bool> SaveChangesAsync()
 {
     return((await _context.SaveChangesAsync()) > 0);
 }