public IActionResult Patch(int dorsal, [FromBody] PatchValue value)
        {
            var piloto = _context.Pilotos.FirstOrDefault(t => t.Dorsal == dorsal);

            if (piloto == null)
            {
                return(NotFound());
            }

            switch (value.Name)
            {
            case "Nombre":
                piloto.Nombre = value.Value;
                break;

            case "Apellido":
                piloto.Apellido = value.Value;
                break;

            case "Pais":
                piloto.Pais = value.Value;
                break;

            default:
                return(new NoContentResult());
            }


            _context.Pilotos.Update(piloto);
            _context.SaveChanges();

            return(new NoContentResult());
        }
Exemplo n.º 2
0
        public IActionResult Patch(int id, [FromBody] PatchValue property)
        {
            var todoItem = _context.TodoItems.FirstOrDefault(ti => ti.Id == id);

            if (todoItem == null)
            {
                return(NotFound());
            }

            //Posible Values
            var name       = "Name";
            var isComplete = "IsComplete";

            if (name.Equals(property.Key, StringComparison.InvariantCultureIgnoreCase))
            {
                todoItem.Name = property.Value;
            }
            else if (isComplete.Equals(property.Key, StringComparison.InvariantCultureIgnoreCase))
            {
                todoItem.IsComplete = Convert.ToBoolean(property.Value);
            }
            else
            {
                return(NotFound());
            }

            //Este no controla los strings
            //switch (property.Key)
            //{
            //    case "Name":
            //        todoItem.Name = property.Value;
            //        break;

            //    case "IsComplete":
            //        todoItem.IsComplete = Convert.ToBoolean(property.Value);
            //        break;

            //    default:
            //        return NotFound();
            //}


            _context.TodoItems.Update(todoItem);
            _context.SaveChanges();

            return(new NoContentResult());
        }
        public IActionResult Patch(int dorsal, [FromBody] PatchValue value)
        {
            var monoplaza = _context.Monoplazas.FirstOrDefault(t => t.Dorsal == dorsal);

            if (monoplaza == null)
            {
                return(NotFound());
            }

            switch (value.Name)
            {
            case "Nombre":
                monoplaza.Nombre = value.Value;
                break;

            case "Color":
                monoplaza.Color = value.Value;
                break;

            case "Potencia":

                int  newPotencia = 0;
                bool response    = int.TryParse(value.Value, out newPotencia);

                monoplaza.Potencia = newPotencia;

                break;

            default:
                return(new NoContentResult());
            }


            _context.Monoplazas.Update(monoplaza);
            _context.SaveChanges();

            return(new NoContentResult());
        }