public async Task <IActionResult> BanAsync(string userId, BanTerm banTerm) { await _userService.BanAsync(userId, banTerm); _logger.LogDebug($"Ban user: {userId} on term {banTerm.ToString()}"); return(RedirectToAction("Index", "Home")); }
public async Task BanAsync(string userId, BanTerm term) { var timeSpanTerm = term == BanTerm.Permanent ? TimeSpan.MaxValue : TimeSpan.FromMinutes((double)term); var user = await _userRepository.FindSingleAsync(u => u.Id == userId); if (user == null) { throw new EntityNotFoundException <User>(userId); } user.BannedTo = DateTime.UtcNow + timeSpanTerm; await _userRepository.UpdateAsync(user); await _unitOfWork.CommitAsync(); }