public List <JudgeDto> GetJudges(string raceId, JudgePrincipal principal) { if (string.IsNullOrEmpty(raceId)) { throw new ArgumentNullException("Missing RaceId"); } var isAdmin = principal != null && principal.Judge.IsAdmin; var judgesRepository = repositorySetProvider.GetRepositorySet(raceId).Judges; var judges = new List <JudgeDto>(); foreach (var judge in judgesRepository.GetJudges()) { var dto = new JudgeDto(); dto.JudgeId = judge.JudgeId; dto.JudgeName = judge.Name; dto.IsAdmin = judge.IsAdmin; if (isAdmin) { dto.DeviceIds = new List <string>(); foreach (var judgeDevice in judgesRepository.FindJudgesDevices(judge.JudgeId)) { dto.DeviceIds.Add(judgeDevice.DeviceId); } } judges.Add(dto); } return(judges); }
public JudgeDto Authorize(string raceId, AuthorizeRequestDto authorization) { if (string.IsNullOrEmpty(raceId)) { throw new ArgumentNullException("Missing RaceId"); } if (string.IsNullOrEmpty(authorization.ConnectCode)) { throw new ArgumentNullException("Missing ConnectCode"); } if (string.IsNullOrEmpty(authorization.JudgeId)) { throw new ArgumentNullException("Missing JudgeId"); } if (string.IsNullOrEmpty(authorization.JudgeName)) { throw new ArgumentNullException("Missing JudgeName"); } var judgesRepository = repositorySetProvider.GetRepositorySet(raceId).Judges; var judgesDevice = judgesRepository.FindConnectCode(authorization.ConnectCode); if (judgesDevice == null) { throw new ArgumentOutOfRangeException("Unknown ConnectCode"); } ModelJudge judge = judgesRepository.FindJudge(authorization.JudgeId); if (judge == null) { judge = new ModelJudge(); judge.JudgeId = authorization.JudgeId; judge.Name = authorization.JudgeName; judgesRepository.SaveJudge(judge); } judgesDevice.AuthenticationToken = AuthenticationToken.Generate(raceId, judge.JudgeId).ToString(); judgesDevice.JudgeId = judge.JudgeId; judgesRepository.SaveJudgeDevice(judgesDevice); JudgeDto judgeDto = new JudgeDto(); judgeDto.JudgeId = judge.JudgeId; judgeDto.JudgeName = judge.Name; judgeDto.IsAdmin = judge.IsAdmin; judgeDto.DeviceIds = new List <string>(); foreach (var judgeDevice in judgesRepository.FindJudgesDevices(judge.JudgeId)) { judgeDto.DeviceIds.Add(judgeDevice.DeviceId); } return(judgeDto); }
public JudgeDto Unauthorize(string raceId, UnauthorizeRequestDto authorization) { if (string.IsNullOrEmpty(raceId)) { throw new ArgumentNullException("Missing RaceId"); } if (string.IsNullOrEmpty(authorization.JudgeId)) { throw new ArgumentNullException("Missing JudgeId"); } var judgesRepository = repositorySetProvider.GetRepositorySet(raceId).Judges; var judge = judgesRepository.FindJudge(authorization.JudgeId); if (judge == null) { throw new ArgumentOutOfRangeException("Unknown JudgeId"); } foreach (var device in judgesRepository.FindJudgesDevices(judge.JudgeId)) { var shouldRemove = string.IsNullOrEmpty(authorization.DeviceId) || authorization.DeviceId == device.DeviceId; if (shouldRemove) { device.AuthenticationToken = null; device.JudgeId = null; judgesRepository.SaveJudgeDevice(device); } } JudgeDto judgeDto = new JudgeDto(); judgeDto.JudgeId = judge.JudgeId; judgeDto.JudgeName = judge.Name; judgeDto.IsAdmin = judge.IsAdmin; judgeDto.DeviceIds = new List <string>(); foreach (var judgeDevice in judgesRepository.FindJudgesDevices(judge.JudgeId)) { judgeDto.DeviceIds.Add(judgeDevice.DeviceId); } return(judgeDto); }