public async Task <IActionResult> AddAsync([FromBody] Customer customer) { if (customer == null) { return(BadRequest($"{nameof(customer)} cannot be null")); } string msg = string.Empty; if (!ModelState.IsValid) { return(BadRequest("Complete and correct all required fields and try again!")); } if (ModelState.IsValid) { var result = await _dataStore.AddCustomerAsync(customer); msg = result.Message; if (result.Succeeded) { var json = new JsonResponse { Json = result.Customer, Message = msg }; return(Ok(json)); } } return(BadRequest(msg)); }
public InventoryMutation(IDataStore dataStore) { Field <ItemType>( "createItem", arguments: new QueryArguments( new QueryArgument <NonNullGraphType <ItemInputType> > { Name = "item" } ), resolve: context => dataStore.AddItemAsync(context.GetArgument <Item>("item"))); Field <CustomerType>( "createCustomer", arguments: new QueryArguments( new QueryArgument <NonNullGraphType <CustomerInputType> > { Name = "customer" } ), resolve: context => dataStore.AddCustomerAsync(context.GetArgument <Customer>("customer"))); Field <OrderType>( "createOrder", arguments: new QueryArguments( new QueryArgument <NonNullGraphType <OrderInputType> > { Name = "order" } ), resolve: context => dataStore.AddOrderAsync(context.GetArgument <Order>("order"))); Field <OrderItemType, OrderItem>() .Name("createOrderItem") .Argument <NonNullGraphType <OrderItemInputType> >("orderitem", "orderitem input") .ResolveAsync(ctx => dataStore.AddOrderItemAsync(ctx.GetArgument <OrderItem>("orderitem"))); }
public InventoryMutation(IDataStore store) { Field <ItemType, Item>() .Name("createItem") .Argument <NonNullGraphType <ItemInputType> >("item", "item input") .ResolveAsync(ctx => { var item = ctx.GetArgument <Item>("item"); return(store.AddItemAsync(item)); } ); Field <OrderType, Order>() .Name("createOrder") .Argument <NonNullGraphType <OrderInputType> >("order", "order input") .ResolveAsync(ctx => { var order = ctx.GetArgument <Order>("order"); return(store.AddOrderAsync(order)); }); Field <CustomerType, Customer>() .Name("createCustomer") .Argument <NonNullGraphType <CustomerInputType> >("customer", "customer input") .ResolveAsync(ctx => { var customer = ctx.GetArgument <Customer>("customer"); return(store.AddCustomerAsync(customer)); }); Field <OrderItemType, OrderItem>() .Name("addOrderItem") .Argument <NonNullGraphType <OrderItemInputType> >("orderitem", "orderitem input") .ResolveAsync(ctx => { var orderItem = ctx.GetArgument <OrderItem>("orderitem"); return(store.AddOrderItemAsync(orderItem)); }); }