Exemplo n.º 1
0
        private Response HandleRegisterParticipant(Request request)
        {
            try
            {
                List <String> trials = new List <string>();
                foreach (var requestTrial in request.Trials)
                {
                    trials.Add(requestTrial);
                }
                _participantService.RegisterParticipant(request.ParticipantName, request.ParticipantAge, trials);
                AgeCategoryDTO ageCategoryDto =
                    ProtoUtils.AgeCategoryToDto(_ageCategoryService.FindSuitableAgeCategory(request.ParticipantAge.ToString()));

                // notify

                foreach (var key in _loggedClients.Keys)
                {
                    if (!key.Equals(request.Username))
                    {
                        _loggedClients[key].WriteAsync(new Response
                        {
                            ResponseType     = ResponseType.UpdateResponse,
                            RegisteredTrials = { request.Trials },
                            AgeCategoryName  = ageCategoryDto.Name
                        });
                    }
                }

                return(new Response
                {
                    ResponseType = ResponseType.OkResponse,
                    AgeCategoryName = ageCategoryDto.Name,
                    RegisteredTrials = { request.Trials }
                });
            }
            catch (CustomException e)
            {
                return(new Response {
                    ResponseType = ResponseType.FailureResponse, ErrorMessage = e.Message
                });
            }
        }