Esempio n. 1
0
        public bool IsValid(EatableInput request)
        {
            if (request == null || String.IsNullOrEmpty(request.Name) || request.Price < 0)
            {
                return(false);
            }

            return(true);
        }
Esempio n. 2
0
        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()));
        }
Esempio n. 3
0
        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));
        }