示例#1
0
        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"));
        }
示例#2
0
        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();
        }