Ejemplo n.º 1
0
        public async Task <IActionResult> Edit(int id, [Bind("IdComponente,NomeComponente,TempoProduzione,IdArticolo")] ComponenteArticolo componenteArticolo)
        {
            if (id != componenteArticolo.IdComponente)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(componenteArticolo);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ComponenteArticoloExists(componenteArticolo.IdComponente))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["IdArticolo"] = new SelectList(_context.Articoli, "IdArticolo", "NomeArticolo", componenteArticolo.IdArticolo);
            return(View(componenteArticolo));
        }
        public async Task <IActionResult> Put([FromRoute] int id, [FromBody] ComponenteArticolo componente)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != componente.IdComponente)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> Create([Bind("IdComponente,NomeComponente,TempoProduzione,IdArticolo")] ComponenteArticolo componenteArticolo)
        {
            if (ModelState.IsValid)
            {
                _context.Add(componenteArticolo);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["IdArticolo"] = new SelectList(_context.Articoli, "IdArticolo", "NomeArticolo", componenteArticolo.IdArticolo);
            return(View(componenteArticolo));
        }
        public async Task <IActionResult> Post([FromBody] ComponenteArticolo componente)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            componente.IdComponente = 0;
            _context.ComponentiArticolo.Add(componente);
            await _context.SaveChangesAsync();

            return(Ok(componente));
        }