public InventoryMutation(IItemRepo itemRepo) { FieldAsync <ItemType>( "createItem", arguments: new QueryArguments(new QueryArgument <NonNullGraphType <CreateItemInputType> > { Name = "createItem" }), resolve: async context => { var item = context.GetArgument <Item>("createItem"); return(await context.TryAsyncResolve(async c => (await itemRepo.Add(new List <Item> { item })).FirstOrDefault())); } ); FieldAsync <ItemType>( "updateItem", arguments: new QueryArguments(new QueryArgument <NonNullGraphType <UpdateItemInputType> > { Name = "updateItem" }), resolve: async context => { var item = context.GetArgument <Item>("updateItem"); return(await context.TryAsyncResolve(async c => (await itemRepo.Update(new List <Item> { item })).FirstOrDefault())); } ); }
public int Add(Item item) { if (DateTime.Compare(item.DueDate, DateTime.Now) < 0) { return(0); } return(itemRepo.Add(item)); }
public IActionResult Create([FromBody] Item model) { if (model == null || !ModelState.IsValid) { return(BadRequest()); } _repo.Add(model); return(CreatedAtAction("Create", model)); }
public ActionResult Create() { int newId = _itemRepo.GetAll().Max(i => i.Id) + 1; Item newItem = new Item(); newItem.Id = newId; newItem.ItemName = " New:" + newId; newItem.Quantity = 1; _itemRepo.Add(newItem); return(RedirectToAction("Index")); }