Exemplo n.º 1
0
        public async Task <IActionResult> PostListproduct([FromBody] Listproduct listproduct)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            _context.ListProduct.Add(listproduct);
            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateException)
            {
                if (ListproductExists(listproduct.IdList))
                {
                    return(new StatusCodeResult(StatusCodes.Status409Conflict));
                }
                else
                {
                    throw;
                }
            }

            return(CreatedAtAction("GetListproduct", new { id = listproduct.IdList }, listproduct));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> PutListproduct([FromRoute] int id, [FromBody] Listproduct listproduct)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != listproduct.IdList)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }