public void Delete(int id)
        {
            Restaurant restaurant;

            restaurant = _context.Restaurants.FirstOrDefault(r => r.Id == id);
            _context.Remove(restaurant);
            _context.SaveChanges();
        }
Esempio n. 2
0
        public async Task <bool> DeleteAsync(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 item = await _context.PeriodicElements.SingleOrDefaultAsync(c => c.Id == id);

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