Example #1
0
        public IQueryable DeleteCategory([FromBody] TodoCategory category)
        {
            var categoryToBeDeleted = _context.Categories.SingleOrDefault(e => e.Id == category.Id);

            if (categoryToBeDeleted != null)
            {
                var itemsToBeDeleted = _context.TodoItems.Where(e => e.Category == category.Id).ToArray();
                if (itemsToBeDeleted.Length > 0)
                {
                    _context.RemoveRange(itemsToBeDeleted);
                    _context.SaveChanges();
                }

                _context.Remove(categoryToBeDeleted);
                _context.SaveChanges();
            }

            return(_context.Categories);
        }