public IActionResult CreateItem([FromBody] ItemCreateModel item) { if (item == null || !ModelState.IsValid) { return(BadRequest(ModelState)); } var newItem = new ItemDataTransferObject { Name = item.Name, Code = item.Code, Price = item.Price, Category = item.Category }; var newItemId = _itemService.CreateItem(newItem); return(CreatedAtRoute("GetItem", new { id = newItemId }, new ItemGetModel { Id = newItemId, Name = newItem.Name, Code = newItem.Code, Price = newItem.Price, Category = newItem.Category })); }
private int AddItem() { var id = _itemsService.CreateItem(new Item { Name = "My Test Item " + Guid.NewGuid(), Type = "service", PriceModel = new ItemPriceModel { Base = 295.95F, PayCycle = "mon", PriceModel = "fla" } }).Id; return(id); }
public async Task <IActionResult> Create(ItemsViewModel item) { Items itemDB = new Items { itemid = Guid.NewGuid(), partnum = item.PartNum, price = item.Price, prodid = item.ProdId, productname = item.ProductName, quantity = item.Quantity }; itemDB = await Task.Run(() => itemDB = itemsService.CreateItem(itemDB)); return(Ok(itemDB)); }
public ActionResult <ItemModel> CreateItem([FromBody] ItemModel newItem) { try { if (!ModelState.IsValid) //if invalid { return(BadRequest(ModelState)); } var item = _itemsService.CreateItem(newItem); return(Created($"api/items/{item.Id}", item)); } catch (Exception) { return(StatusCode(StatusCodes.Status500InternalServerError, "Something unexpected happened.")); } }