public string Reset() { var votes = _context.Votes.ToList(); var history = _context.History.ToList(); _context.RemoveRange(votes); _context.RemoveRange(history); _context.SaveChanges(); return("Reset OK!"); }
/// <inheritdoc /> /// <exception cref="UserNotFoundException">Thrown when user is not found</exception> public async Task RemoveUserByIdAsync(string userId) { var userToRemove = await _userManager.FindByIdAsync(userId); if (userToRemove == null) { throw new UserNotFoundException(); } await _db.Entry(userToRemove).Collection(u => u.Todos).LoadAsync(); // Clear cached todos owned by the user foreach (var todo in userToRemove.Todos) { _cache.Remove(CacheConstants.GetSingleTodoCacheKey( todo.Id, userToRemove.Id)); _cache.Remove(CacheConstants.GetAllTodosForDayCacheKey( userToRemove.Id, todo.Due.Date)); } _cache.Remove(CacheConstants.GetAllTodosCacheKey(userToRemove.Id)); _db.RemoveRange(userToRemove.Todos); await _userManager.DeleteAsync(userToRemove); await _db.SaveChangesAsync(); // Clear user if cached and all user list. _cache.Remove(CacheConstants.GetSingleUserCacheKey(userToRemove.Id)); _cache.Remove(CacheConstants.AllUsersCacheKey); }
public async Task <Unit> Handle(DeleteManyCommand request, CancellationToken cancellationToken) { var dimensions = _context.Dimensions.Where(d => request.Ids.Contains(d.Id)); if (!dimensions.Any()) { throw new DimensionNotFoundException(request.Ids); } _context.RemoveRange(dimensions); var success = await _context.SaveChangesAsync() > 0; if (success) { return(Unit.Value); } throw new Exception("Problem saving changes."); }
public async Task <Unit> Handle(DeleteManyEditionCommand request, CancellationToken cancellationToken) { var bookEditions = _context.BookEditions.Where(b => request.Isbns.Contains(b.Isbn)); if (!bookEditions.Any()) { throw new BookEditionNotFoundException(request.Isbns); } _context.RemoveRange(bookEditions); var success = await _context.SaveChangesAsync() > 0; if (success) { return(Unit.Value); } throw new Exception("Problem saving changes."); }