Example #1
0
        public async Task <IActionResult> Get(QueryTrains.Request request)
        {
            if (request == null)
            {
                return(BadRequest($"{typeof(QueryTrains.Request)} is null"));
            }

            try
            {
                var session = _ssp.Create(TimeSpan.FromDays(1));

                var result = await _rail.QueryTrainsAsync(session, request);

                await _ssp.SaveAsync(session);

                return(Ok(new GetTrainsResult
                {
                    SessionId = session.Id,
                    Trains = result.Trains
                }));
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, "GetTrains failed");

                return(StatusCode(500));
            }
        }
        public async Task <IActionResult> Create([FromBody] QueryReserveCreate.Request request)
        {
            if (request == null)
            {
                return(BadRequest(ModelState));
            }

            _logger.LogInformation($"Rail reserve attempt SessionId: {request.Option.SessionId}, CarOptionRef: {request.Option.CarOptionRef}");

            var session = await _ssp.LoadAsync(request.Option.SessionId);

            if (session == null)
            {
                return(SessionExpired());
            }

            try
            {
                var result = await _rail.CreateReserveAsync(session, request);

                await _ssp.SaveAsync(session);

                return(Ok(result));
            }
            catch (Services.PassRzdRu.Parser.ParserException ex)
            {
                _logger.LogError(LogEventId.RESERVE_TICKET_FAIL, ex, $"{nameof(_rail.CreateReserveAsync)} failed, SessionId: {session.Id}, Request: {request}");
                return(StatusCode((int)HttpStatusCode.InternalServerError, new { message = ex.Message }));
            }
            catch (Exception ex)
            {
                _logger.LogError(LogEventId.RESERVE_TICKET_FAIL, ex, $"{nameof(_rail.CreateReserveAsync)} failed, SessionId: {session.Id}, Request: {request}");
                return(BadRequest());
            }
        }