public async Task <IHttpActionResult> CreateQuery(TinyQuery tQuery) { int queryId = 0; if (!ModelState.IsValid) { return(BadRequest(ModelState)); } tQuery.UserName = RequestContext.Principal.Identity.Name; try { queryId = await this.QueryManager.CreateQueryAsync(tQuery); } catch (Exception ex) { //May do something return(BadRequest()); } Uri locationheader = new Uri(Url.Link("GetQueryById", new { id = queryId })); return(Created(locationheader, tQuery)); }
public void OnGraphInit(IObjectGraphType query, IObjectGraphType mutation) { var orderService = shopFactory.OrderService; //var orderResolver = new OrderResolver(orderService); var orderResolver = new FuncFieldResolver <IOrder>((ctx) => orderService.GetOrder(ctx.GetArgument <string>("id"))); //var orderArticleResolver = new FuncFieldResolver<IEnumerable<IOrderArticle>>((ctx) => (ctx.Source as IOrder).Articles); var order = shopFactory.CreateInstance <IOrder>(); var orderArticle = shopFactory.CreateInstance <IOrderArticle>(); GraphTypeTypeRegistry.Register(typeof(IOrderArticle), typeof(ReflectionObjectGraphType <IOrderArticle>)); query.AddField(new FieldType() { Name = "orderarticle", //Resolver = orderResolver, Type = orderArticle.GetType(), ResolvedType = new ReflectionObjectGraphType <IOrderArticle>() }); query.AddField(new FieldType() { Name = "order", Resolver = orderResolver, Arguments = TinyQuery.GetIdQuery(), Type = order.GetType(), ResolvedType = new ReflectionObjectGraphType <IOrder>() }); }
public async Task <int> CreateQueryAsync(TinyQuery tQuery) { var query = new Query { Title = tQuery.Title, Description = tQuery.Description, Script = tQuery.Script, UserName = tQuery.UserName }; _context.Queries.Add(query); await _context.SaveChangesAsync(); return(query.QueryId); }