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 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 }); } }
public PlanetMutations(IPlanetService service) { FieldAsync <ActionResponseType>( CREATE_REQUEST_ENDPOINT, "Creates a new Planet", new QueryArguments( new QueryArgument <NonNullGraphType <PlanetCreateViewModel> > { Name = UPDATE_CREATE_ARGUMENT_NAME, Description = "Planet Entity to be Created" }), async context => { var planet = context.GetArgument <Planet>(UPDATE_CREATE_ARGUMENT_NAME); try { await service.CreatePlanetAsync(planet); } catch (ValidationException e) { context.Errors.Add(new ExecutionError(e.Message)); return(new ActionResponse(false)); } catch (Exception) { context.Errors.Add(new ExecutionError("Server Error")); return(new ActionResponse(false)); } return(new ActionResponse(true, planet.Id)); }); FieldAsync <ActionResponseType>( UPDATE_REQUEST_ENDPOINT, "Updates an existing Planet", new QueryArguments( new QueryArgument <NonNullGraphType <PlanetUpdateViewModel> > { Name = UPDATE_CREATE_ARGUMENT_NAME, Description = "Planet to be Updated" }), async context => { var planet = context.GetArgument <Planet>(UPDATE_CREATE_ARGUMENT_NAME); try { await service.UpdatePlanetAsync(planet); } catch (ValidationException e) { context.Errors.Add(new ExecutionError(e.Message)); return(new ActionResponse(false)); } catch (Exception) { context.Errors.Add(new ExecutionError("Server Error")); return(new ActionResponse(false)); } return(new ActionResponse(true, planet.Id)); }); FieldAsync <ActionResponseType>( DELETE_REQUEST_ENDPOINT, "Removes an existing Planet", new QueryArguments( new QueryArgument <GuidGraphType> { Name = DELETE_ARGUMENT_NAME, Description = "Planet Id used to identify which planet will be deleted" }), async context => { var id = context.GetArgument <Guid>(DELETE_ARGUMENT_NAME); try { await service.DeletePlanetAsync(id); } catch (ValidationException e) { context.Errors.Add(new ExecutionError(e.Message)); return(new ActionResponse(false)); } catch (Exception) { context.Errors.Add(new ExecutionError("Server Error")); return(new ActionResponse(false)); } return(new ActionResponse(true)); }); }