コード例 #1
0
        public async Task <IActionResult> PutConsulta([FromRoute] int id, [FromBody] Consulta consulta)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

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

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

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

            return(NoContent());
        }
コード例 #2
0
        public async Task <IActionResult> PutConsulta(int id, Consulta consulta)
        {
            if (id != consulta.Id_Consulta)
            {
                return(BadRequest());
            }
            if (consulta.Dat_Inicio_Consulta < consulta.Dat_Fim_Consulta)
            {
                return(BadRequest());
            }

            if (_context.Consultas.Any(x => x.Dat_Inicio_Consulta <= consulta.Dat_Inicio_Consulta && x.Dat_Fim_Consulta >= consulta.Dat_Fim_Consulta))
            {
                return(BadRequest());
            }
            _context.Entry(consulta).State = EntityState.Modified;

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

            return(NoContent());
        }