public async Task <ActionResult <Persona> > Post(Persona persona)
        {
            _context.Personas.Add(persona);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("Post", new { DNI = persona.DNI }, persona));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> Eliminar(int id)
        {
            var ProductoActual = await DB.Producto.FirstOrDefaultAsync(elem => elem.Id == id);

            if (ProductoActual == null)
            {
                return(Json(new { success = false, mensaje = "Error al intentar eliminar el registro" }));
            }
            DB.Producto.Remove(ProductoActual);
            await DB.SaveChangesAsync();

            return(Json(new { success = true, mensaje = "Se eliminó el registro" }));
        }
Exemplo n.º 3
0
        public async Task <IActionResult> OnPostEliminar(int id)
        {
            var ProductoAeliminar = await DB.Producto.FindAsync(id);

            if (ProductoAeliminar == null)
            {
                return(NotFound());
            }
            DB.Producto.Remove(ProductoAeliminar);
            await DB.SaveChangesAsync();

            return(RedirectToPage("Index"));
        }
Exemplo n.º 4
0
        public async Task <IActionResult> OnPost()
        {
            if (ModelState.IsValid)
            {
                var ProductoDesdeLaDB = await DB.Producto.FindAsync(Producto.Id);

                ProductoDesdeLaDB.Nombre = Producto.Nombre;
                ProductoDesdeLaDB.Precio = Producto.Precio;
                await DB.SaveChangesAsync();

                return(RedirectToPage("Index"));
            }
            return(RedirectToPage());
        }
Exemplo n.º 5
0
        public async Task <IActionResult> OnPost()
        {
            if (ModelState.IsValid)
            {
                await DB.Producto.AddAsync(Producto);

                await DB.SaveChangesAsync();

                return(RedirectToPage("Index"));
            }
            else
            {
                return(Page());
            }
        }