コード例 #1
0
        public async Task <ActionResult> Delete(Guid id)
        {
            var existingProduct = await _dbContext.Products.FindAsync(id);

            if (existingProduct is null)
            {
                return(NotFound());
            }

            _dbContext.Remove(existingProduct);
            await _dbContext.SaveChangesAsync();

            return(NoContent());
        }
コード例 #2
0
        public async Task <ActionResult <Product> > Delete(int id)
        {
            var product = await _productsDbContext.Products.FindAsync(id);

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

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

            return(Ok(product));
        }
コード例 #3
0
 public async void DeleteList(List <T> list)
 {
     try
     {
         foreach (var record in list)
         {
             _context.Remove(record);
         }
         await _context.SaveChangesAsync();
     }
     catch (Exception)
     {
         throw;
     }
 }
コード例 #4
0
        /// <summary>
        /// Delete product from database
        /// </summary>
        /// <param name="id"></param>
        /// <returns>True if successful, else false</returns>
        public async Task <bool> DeleteProductAsync(Guid id)
        {
            var product = _context.Product.Find(id);

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

                    return(true);
                }
                catch (Exception)
                {
                    // _logger.LogInformation("DeleteProductAsync Exeption", ex.Message);
                    return(false);
                }
            }

            return(false);
        }
コード例 #5
0
 public void DeleteWorkStock(WorkStock workStock)
 {
     context.Remove(workStock);
     context.SaveChanges();
 }
コード例 #6
0
 public void RemoveProduct(Product product)
 {
     _context.Remove(product);
 }