public bool IsValid(EatableInput request) { if (request == null || String.IsNullOrEmpty(request.Name) || request.Price < 0) { return(false); } return(true); }
public IHttpActionResult Put(int id, [FromBody] EatableInput input) { if (!_eatableValidator.IsValid(input)) { throw new HttpResponseException(System.Net.HttpStatusCode.BadRequest); } _inventoryService.Update(id, Mapper.Map <Eatable>(input)); return(Ok(_inventoryService.Get())); }
public IHttpActionResult Post([FromBody] EatableInput input) { if (!_eatableValidator.IsValid(input)) { throw new HttpResponseException(System.Net.HttpStatusCode.BadRequest); } var newEatableItem = _inventoryService.Insert(Mapper.Map <Eatable>(input)); return(Ok(newEatableItem)); }