Example #1
0
        public async Task <Product> Remove(int id)
        {
            var product = await GetById(id);

            _context.Remove(product);
            await _context.SaveChangesAsync();

            return(product);
        }
        public async Task <IActionResult> Delete(int id)
        {
            var product = await _productsContext.Products.FindAsync(id);

            if (product == null)
            {
                return(NoContent());
            }
            _productsContext.Remove(product);
            await _productsContext.SaveChangesAsync();

            return(Ok());
        }
        public async Task <IActionResult> DeleteAsync(Guid id)
        {
            var product = await _context.Products.FindAsync(id);

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

            _context.Remove(product);
            await _context.SaveChangesAsync();

            return(NoContent());
        }
Example #4
0
        public async Task <bool> Delete(int id)
        {
            bool  isDeleted = false;
            Order order     = await GetOrderById(id)
                              .Include(o => o.ProductOrder)
                              .FirstOrDefaultAsync();

            if (order != null)
            {
                _context.Remove(order);
                await _context.SaveChangesAsync();

                isDeleted = true;
            }

            return(isDeleted);
        }
Example #5
0
        public override async Task <DeleteProductResponse> DeleteProduct(DeleteProductRequest request, ServerCallContext context)
        {
            var product = await _productsContext.Product.FindAsync(request.ProductId);

            if (product == null)
            {
                throw new RpcException(new Status(StatusCode.NotFound, $"Product with ID={request.ProductId} is not found."));
            }
            _productsContext.Remove(product);
            var deleteCount = await _productsContext.SaveChangesAsync();

            var response = new DeleteProductResponse
            {
                Success = deleteCount > 0
            };

            return(response);
        }
Example #6
0
        // Xóa sản phẩm có ProductID = id
        public static async Task DeleteProduct(int id)
        {
            using (var context = new ProductsContext())
            {
                // context.SetLogging();
                var product = await(from p in context.products
                                    where (p.ProductId == id)
                                    select p
                                    )
                              .FirstOrDefaultAsync();   // Lấy  Product có  ID  chỉ  ra

                if (product != null)
                {
                    context.Remove(product);
                    Console.WriteLine($"Xóa {product.ProductId}");
                    await context.SaveChangesAsync();
                }
            }
        }
Example #7
0
        public async Task <TEntity> DeleteAsync(TEntity entity)
        {
            if (entity == null)
            {
                throw new ArgumentNullException($"{nameof(AddAsync)} entity must not be null");
            }

            try
            {
                RepositoryContext.Remove(entity);
                await RepositoryContext.SaveChangesAsync();

                return(entity);
            }
            catch (Exception ex)
            {
                throw new Exception($"{nameof(entity)} could not be deleted: {ex.Message}");
            }
        }
Example #8
0
 public async Task Delete(int id)
 {
     try
     {
         var product = _products.products1.Find(id);
         if (product != null)
         {
             _products.Remove(product);
             await _products.SaveChangesAsync();
         }
     }
     catch (DbUpdateConcurrencyException ex)
     {
         Console.WriteLine(ex.Message);
         throw;
     }
     catch (DbUpdateException e)
     {
         Console.WriteLine(e.Message);
         throw;
     }
 }