Exemplo n.º 1
0
        public async Task <ActionResult <Product> > Excute()
        {
            AssigndataUtils AssigndataUtils = new AssigndataUtils();
            var             _context        = new TGDDContext();

            Product newProduct = await AssigndataUtils.AssignProduct(productDTO, 0);

            _context.Products.Add(newProduct);
            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateException)
            {
                bool productExist = _context.Products.Any(p => p.Id == newProduct.Id);
                if (productExist)
                {
                    return(Conflict());
                }
                else
                {
                    throw;
                }
            }
            return(CreatedAtAction("GetProducts", new { id = newProduct.Id }, newProduct));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> Excute()
        {
            AssigndataUtils AssigndataUtils = new AssigndataUtils();
            var             _context        = new TGDDContext();

            Product pro = await AssigndataUtils.AssignProduct(ProductDTO, id);

            //List<Description> tmp = pro.Descriptions.ToList() ;


            //foreach(Description description in tmp)
            //{
            //    _context.Entry((Description)description) = EntityState.Modified;
            //}

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

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                bool productExist = _context.Products.Any(p => p.Id == pro.Id);
                if (!productExist)
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(200));
        }