コード例 #1
0
        public async Task <bool> DeleteCustomerAsync(int id)
        {
            //Extra hop to the database but keeps it nice and simple for this demo
            //Including orders since there's a foreign-key constraint and we need
            //to remove the orders in addition to the customer
            var customer = await _Context.Customers
                           .Include(c => c.Orders)
                           .SingleOrDefaultAsync(c => c.Id == id);

            _Context.Remove(customer);
            try
            {
                return(await _Context.SaveChangesAsync() > 0 ? true : false);
            }
            catch (System.Exception exp)
            {
                _Logger.LogError($"Error in {nameof(DeleteCustomerAsync)}: " + exp.Message);
            }

            // **************************************************************************
            // Comment/uncomment the following line when measuring inner loop performance
            await Task.Delay(500);

            return(false);
        }
コード例 #2
0
        public async Task <bool> DeleteCustomerAsync(int id)
        {
            //Extra hop to the database but keeps it nice and simple for this demo
            var customer = await _context.Customers.SingleOrDefaultAsync(c => c.Id == id);

            _context.Remove(customer);
            try
            {
                return(await _context.SaveChangesAsync() > 0 ? true : false);
            }
            catch (System.Exception exp)
            {
                _logger.LogError($"Error in {nameof(DeleteCustomerAsync)}: " + exp.Message);
            }
            return(false);
        }