Esempio n. 1
0
        public async Task <IActionResult> PutOrder(int id, Order order)
        {
            if (id != order.Id)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
        public async Task <IActionResult> PutProduct(int id, ProductDTO product)
        {
            //if (id != product.Id)
            //{
            //    return BadRequest();
            //}

            //_context.Entry(product).State = EntityState.Modified;

            var findProduct = _context.Product
                              .Where(product => product.Id == id)
                              .SingleOrDefault();


            if (findProduct != null)
            {
                if (product.Image == "" || product.Image == null)
                {
                }
                else
                {
                    findProduct.Image = product.Image;
                }
                findProduct.ProductName   = product.ProductName;
                findProduct.Description   = product.Description;
                findProduct.Model         = product.Model;
                findProduct.Color         = product.Color;
                findProduct.Storage       = product.Storage;
                findProduct.Price         = product.Price;
                findProduct.StockQuantity = product.StockQuantity;
                findProduct.ProviderId    = product.ProviderId;

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

                _context.Update(findProduct);


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

            return(NoContent());
        }
        public async Task <IActionResult> UpdateUserAddress(int id, AddressDTO user)
        {
            //if (id != user.Id)
            //{
            //    return BadRequest();
            //}

            var findUser = _context.User.Find(id);

            if (findUser != null)
            {
                findUser.Address     = user.Address;
                findUser.City        = user.City;
                findUser.District    = user.District;
                findUser.HouseNumber = user.HouseNumber;
                findUser.State       = user.State;
                findUser.ZipCode     = user.ZipCode;


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

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



            return(NoContent());
        }