Beispiel #1
0
        public async Task <IActionResult> PutPratos([FromRoute] int id, [FromBody] PratosDTO pratos)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

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

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

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

            return(NoContent());
        }
Beispiel #2
0
        public async Task <IActionResult> PostPratos([FromBody] PratosDTO pratos)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (pratos.IdPratos > 0)
            {
                await PutPratos(pratos.IdPratos, pratos);
            }
            else
            {
                _context.pratos.Add(pratos);
                await _context.SaveChangesAsync();
            }

            return(CreatedAtAction("GetPratos", new { id = pratos.IdPratos }, pratos));
        }