Example #1
0
        public async Task <RabbitResponse> ProcessAsync(string data)
        {
            try
            {
                var request = JObject.Parse(data);
                var(_, response) = await m_planetService.SearchPlanetAsync(new Pagination(), new Ordering(), new PlanetFilter
                {
                    SearchTerm = request["PlanetId"].ToString()
                });

                var planet = response.First();
                planet.PlanetStatus = PlanetStatus.ExplorationInProcess;
                await m_planetService.UpdatePlanetAsync(response.First());

                SendExplorationRequest(planet, request);
                return(new RabbitResponse
                {
                    IsSuccessful = true,
                    Message = string.Empty
                });
            }
            catch
            {
                return(new RabbitResponse
                {
                    IsSuccessful = false,
                    Message = string.Empty
                });
            }
        }
        public PlanetQueries(IPlanetService planetService)
        {
            FieldAsync <ListPlanetsQueryModelType>(
                SEARCH_REQUEST_ENDPOINT,
                "Returns a paginated list of planets",
                new QueryArguments(
                    new QueryArgument <NonNullGraphType <PagedRequestType> > {
                Name = PAGINATION_ARGUMENT_NAME, Description = PagedRequestType.Description
            },
                    new QueryArgument <NonNullGraphType <OrderedRequestType> > {
                Name = ORDERING_ARGUMENT_NAME, Description = OrderedRequestType.Description
            },
                    new QueryArgument <NonNullGraphType <FilteredRequestType <Planet> > > {
                Name = FILTERING_ARGUMENT_NAME, Description = FilteredRequestType <Planet> .Description
            }
                    ),
                async context =>
            {
                var pagination = context.GetArgument <Pagination>(PAGINATION_ARGUMENT_NAME);
                var ordering   = context.GetArgument <Ordering>(ORDERING_ARGUMENT_NAME);
                var filtering  = context.GetArgument <PlanetFilter>(FILTERING_ARGUMENT_NAME);

                var(totalCount, items) = await planetService.SearchPlanetAsync(pagination, ordering, filtering);
                try
                {
                    return(new ListResponse <Planet>
                    {
                        TotalCount = totalCount,
                        Items = items
                    });
                }
                catch (Exception e)
                {
                    context.Errors.Add(new ExecutionError("Server Error"));
                    return(null);
                }
            }
                );
        }
        public async Task <RabbitResponse> ProcessAsync(string data)
        {
            try
            {
                var response = JsonConvert.DeserializeObject <ExplorationResponse>(data);
                var(_, toUpdate) = await m_planetService.SearchPlanetAsync(new Pagination(), new Ordering(), new PlanetFilter
                {
                    SearchTerm = response.Planet.Id.ToString()
                });

                SetPlanetNewValues(toUpdate.First(), response);
                await m_planetService.UpdatePlanetAsync(toUpdate.First());

                return(null);
            }
            catch
            {
                return(new RabbitResponse
                {
                    IsSuccessful = false,
                    Message = string.Empty
                });
            }
        }
Example #4
0
        public async Task <RabbitResponse> ProcessAsync(string data)
        {
            try
            {
                var(_, response) = await m_planetService.SearchPlanetAsync(new Pagination(), new Ordering(), new PlanetFilter
                {
                    SearchTerm = data
                });

                return(new RabbitResponse
                {
                    IsSuccessful = response.Count == 1,
                    Message = response.Count == 1 ? JsonConvert.SerializeObject(response.First()) : string.Empty
                });
            }
            catch
            {
                return(new RabbitResponse
                {
                    IsSuccessful = false,
                    Message = string.Empty
                });
            }
        }