コード例 #1
0
        public void DeleteById(Guid Id)
        {
            var match = _context.ToDoItems.FirstOrDefault(c => c.Id == Id);

            if (match != null && match.CreatedBy.Equals(this._userName, StringComparison.OrdinalIgnoreCase))
            {
                _context.Remove(match);
                _context.SaveChanges();
            }
        }
コード例 #2
0
        public async Task <bool> DeleteItemAsync(Guid id)
        {
            var itemToRemove = toDoDataContext.Todos.Where(n => n.Id == id).FirstOrDefault();

            if (itemToRemove == null)
            {
                throw new Exception($"{nameof(LocalTodoDataStore)}.{nameof(DeleteItemAsync)} called with a non existing id");
            }

            toDoDataContext.Remove(itemToRemove);
            //TODO: Remove related entities

            var res = await toDoDataContext.SaveChangesAsync();

            return(res == 1);
        }