public IActionResult Create([FromBody] Cliente cliente)
        {
            if (cliente == null)
            {
                return(NotFound());
            }

            _context.Cliente.Add(cliente);
            _context.SaveChanges();

            return(new ObjectResult(cliente));
        }
        public IActionResult Create([FromBody] Ubicacion Ubicacion)
        {
            if (Ubicacion == null)
            {
                return(NotFound());
            }

            if (Ubicacion.cliente == null)
            {
                Ubicacion.cliente = _context.Cliente.FirstOrDefault(p => p.id == Ubicacion.idCliente);
            }

            _context.Ubicacion.Add(Ubicacion);
            _context.SaveChanges();

            //return CreatedAtRoute("GetById", new { id = Ubicacion.id }, Ubicacion);
            return(new NoContentResult());
        }
Esempio n. 3
0
        public IActionResult Create([FromBody] Maquina maquina)
        {
            if (maquina == null)
            {
                return(NotFound());
            }

            if (maquina.cliente == null)
            {
                maquina.cliente = _context.Cliente.FirstOrDefault(p => p.id == maquina.idCliente);
            }

            if (maquina.ubicacion == null)
            {
                maquina.ubicacion = _context.Ubicacion.FirstOrDefault(p => p.id == maquina.idUbicacion);
            }
            _context.Maquina.Add(maquina);
            _context.SaveChanges();

            return(new ObjectResult(maquina));
        }
Esempio n. 4
0
        private static void AddTestData(maqUbiContext context)
        {
            context.Cliente.Add(new Cliente {
                id = 1, nombre = "Cliente Test 1"
            });
            context.Cliente.Add(new Cliente {
                id = 2, nombre = "Cliente Test 2"
            });
            context.Cliente.Add(new Cliente {
                id = 3, nombre = "Cliente Test 3"
            });
            context.Cliente.Add(new Cliente {
                id = 4, nombre = "Cliente Test 4"
            });

            context.Ubicacion.Add(new Ubicacion {
                id = 1, ubicacion = "Ubicacion Test 1", idCliente = 1
            });
            context.Ubicacion.Add(new Ubicacion {
                id = 2, ubicacion = "Ubicacion Test 2", idCliente = 2
            });
            context.Ubicacion.Add(new Ubicacion {
                id = 3, ubicacion = "Ubicacion Test 3", idCliente = 3
            });
            context.Ubicacion.Add(new Ubicacion {
                id = 4, ubicacion = "Ubicacion Test 4", idCliente = 4
            });

            context.Maquina.Add(new Maquina {
                id = 1, modelo = "Modelo 1", nSerie = "123456", tipo = "Tipo 1", idCliente = 1, idUbicacion = 1
            });
            context.Maquina.Add(new Maquina {
                id = 2, modelo = "Modelo 2", nSerie = "98745z", tipo = "Tipo 2", idCliente = 2, idUbicacion = 2
            });
            context.Maquina.Add(new Maquina {
                id = 3, modelo = "Modelo 3", nSerie = "79813w", tipo = "Tipo 3", idCliente = 3, idUbicacion = 3
            });
            context.Maquina.Add(new Maquina {
                id = 4, modelo = "Modelo 4", nSerie = "36985t", tipo = "Tipo 4", idCliente = 4, idUbicacion = 4
            });

            context.SaveChanges();
        }