コード例 #1
0
        public async Task <IActionResult> PutCatogory(int id, Catogory catogory)
        {
            if (id != catogory.CatogoryId)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
コード例 #2
0
        public async Task <IActionResult> PutProductOrders(int id, ProductOrders productOrders)
        {
            if (id != productOrders.Id)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
コード例 #3
0
        public async Task <ActionResult <Products> > PutProducts([FromBody] ProductModel productData)
        {
            var id      = _context.Products.Where(x => x.ProductId == productData.ProductId).Select(x => x.Id).FirstOrDefault();
            var product = await _context.Products.FindAsync(id);

            var catId = _context.Catogory.Where(x => x.Catogories == productData.CatogoryName).Select(x => x.CatogoryId).FirstOrDefault();

            try
            {
                if (product == null)
                {
                    return(NotFound());
                }

                product.ProductName = productData.ProductName;
                product.ProductId   = productData.ProductId;
                product.IsDeleted   = false;
                product.PhotoUrl    = productData.PhotoUrl;
                product.Price       = productData.Price;
                product.LaunchDate  = productData.LaunchDate;
                product.IsAvailable = productData.IsAvailable;
                product.CatogoryId  = catId;
                product.Description = productData.Description;

                _context.Products.Update(product);
                await _context.SaveChangesAsync();

                return(product);
            }

            catch (DbUpdateConcurrencyException)
            {
                if (!ProductsExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }
        }
コード例 #4
0
        public async Task <ActionResult <ProductCart> > DeleteProductCart(ProductCart productCart)
        {
            var Id    = _context.ProductCart.Where(x => x.UserId == productCart.UserId && x.CartProductId == productCart.CartProductId).Select(x => x.Id).FirstOrDefault();
            var pCart = await _context.ProductCart.FindAsync(Id);

            if (pCart == null)
            {
                return(NotFound());
            }

            _context.ProductCart.Remove(pCart);
            await _context.SaveChangesAsync();

            return(pCart);
        }