Exemplo n.º 1
0
        public IHttpActionResult AddSingleItem([FromBody] ItemDTO itemDTO)
        {
            try
            {
                if (itemDTO == null)
                {
                    return(BadRequest());
                }

                var itemToAdd = _itemMapper.CreateItemFromItemDTO(itemDTO);

                var result = (RepositoryActionResult <ITEM>)_uOW.ITEMs.Insert(itemToAdd);

                if (result.Status == RepositoryActionStatus.Created)
                {
                    var newItem = _itemMapper.CreateItemDTOFromItem(result.Entity);

                    return(Created(Request.RequestUri + "/" + newItem.ItemID.ToString(), newItem));
                }

                return(BadRequest());
            }
            catch (Exception)
            {
                return(InternalServerError());
            }
        }