Exemple #1
0
        private void GetText(ApiInputQuery query, out string text)
        {
            if (query.Session.New)
            {
                text = _queryService.Add(_mapper.Map <Session>(query.Session));
            }
            else
            {
                var currentSession = _sessionService.Get(query.Session.SessionId);
                int playersCount   = _playerService.GetAll(currentSession.Id).Count();

                var player = query.Request.NLU.Entities
                             .Where(t => t["type"].ToObject <string>() == "YANDEX.FIO")
                             .Select(t => new Player
                {
                    Name          = t["value"]["first_name"].ToObject <string>(),
                    SessionId     = currentSession.Id,
                    NumberInQueue = playersCount,
                })
                             .FirstOrDefault();

                var tokens = query.Request.NLU.Tokens;

                switch (currentSession.Status)
                {
                case SessionStatus.New:

                    text = _queryService.HandleNewSession(currentSession, player);

                    break;

                case SessionStatus.AddingPlayer:

                    text = _queryService.HandleAddingPlayerSession(currentSession, tokens);

                    break;

                case SessionStatus.RequestingName:

                    text = _queryService.HandleRequestingNameSession(currentSession, player);

                    break;

                case SessionStatus.Playing:

                    text = _queryService.HandlePlayingSession(currentSession);

                    break;

                default:

                    //TODO: refactor this, add exception handling
                    //Important: unreachable code
                    text = "Повторите, пожалуйста";

                    break;
                }
            }
        }
 public ActionResult Add(CreateQueryModel model)
 {
     if (!ModelState.IsValid)
     {
         return(View(model));
     }
     queryService.Add(mapper.Map <QueryCreateDTO>(model));
     ViewBag.Message = "Запрос создан";
     return(View(mapper.Map <QueryCreateDTO>(model)));
 }