public ActionResult Post([FromBody] StoreItem value) { //Validate item if (!ModelState.IsValid) { return(BadRequest(ModelState)); } //Check for duplicate item if (_store.GetItem(value.Name) != null) { return(BadRequest($"An item already exists with the name {value.Name}.")); } StoreItem item = _store.Add(value); return(CreatedAtAction("Get", new { id = item.Name }, item)); }
public ActionResult Post([FromBody] CartItem value) { //validate item if (!ModelState.IsValid) { return(BadRequest(ModelState)); } //item needs set up in store to be valid if (_store.GetItem(value.Name) == null) { return(BadRequest($"The item ({value.Name}) has not been set up.")); } CartItem item = _cart.Add(value); return(CreatedAtAction("Get", new { id = item.Name }, item)); }
public ActionResult Post([FromBody] BogoPromotion value) { //Validate item if (!ModelState.IsValid) { return(BadRequest(ModelState)); } //Check for duplicate item if (_bogos.GetItem(value.Name) != null) { return(BadRequest($"An item already exists with the name {value.Name}.")); } //item needs set up in store to be valid if (_store.GetItem(value.Name) == null) { return(BadRequest($"The item ({value.Name}) has not been set up.")); } BogoPromotion item = _bogos.Add(value); return(CreatedAtAction("Get", new { id = item.Name }, item)); }