Пример #1
0
        public async Task <IActionResult> TakeSeatAsync(int seatId, [FromBody] TakeSeatInput input)
        {
            var cartGrain = _grainFactory.GetGrain <ISeatGrain>(seatId.ToString());
            var requestId = Guid.NewGuid().ToString("N");

            try
            {
                await cartGrain.TakeSeatAsync(input.FromStationId, input.ToStationId, requestId);
            }
            catch (Exception e)
            {
                return(Json(new BlazorJsonResponse {
                    Status = "0", Message = e.Message
                }));
            }

            var fromName = await _stationRepository.GetNameAsync(input.FromStationId);

            var toName = await _stationRepository.GetNameAsync(input.ToStationId);

            return(Json(new BlazorJsonResponse
            {
                Status = "1",
                Message = $"take a seat success {seatId} [{fromName} -> {toName}] with requestId : {requestId}"
            }));
        }
        public async Task <BlazorJsonResponse> TakeSeatAsync([FromBody] TakeSeatInput input)
        {
            var seatId = input.SeatId;

            if (string.IsNullOrEmpty(input.SeatId))
            {
                var random     = new Random();
                var seatNumber = random.Next(0, 10000);
                seatId = $"{input.TrainId}{seatNumber:0000}";
            }

            var cartActor = _actorProxyFactory.GetClaptrap <ISeatActor>(seatId);
            var requestId = Guid.NewGuid().ToString("N");

            try
            {
                await cartActor.TakeSeatAsync(input.FromStationId, input.ToStationId, requestId);
            }
            catch (Exception e)
            {
                return(new BlazorJsonResponse {
                    Status = "0", Message = e.Message
                });
            }

            var fromName = await _stationRepository.GetNameAsync(input.FromStationId);

            var toName = await _stationRepository.GetNameAsync(input.ToStationId);

            return(new BlazorJsonResponse
            {
                Status = "1",
                Message = $"take a seat success {seatId} [{fromName} -> {toName}] with requestId : {requestId}"
            });
        }