public async Task <ActionResult> Suspend([FromBody] Guid id) { var site = await _contextService.CurrentSiteAsync(); var user = await _contextService.CurrentUserAsync(); var command = new SuspendUser { Id = id, SiteId = site.Id, UserId = user.Id }; await _userService.SuspendAsync(command); return(Ok()); }
public async Task SuspendAsync(SuspendUser command) { var user = await _dbContext.Users .FirstOrDefaultAsync(x => x.Id == command.Id && x.Status != UserStatusType.Deleted); if (user == null) { throw new DataException($"User with Id {command.Id} not found."); } user.Suspend(); _dbContext.Events.Add(new Event(command.SiteId, command.UserId, EventType.Suspended, typeof(User), command.Id)); await _dbContext.SaveChangesAsync(); }