Exemplo n.º 1
0
        public IHttpActionResult PostAsset(AssetViewModel vm)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            var asset = _inventory.CreateAsset(vm.SerialNumber, vm.Description);
            vm.Id = asset.Id;

            return CreatedAtRoute("GetAsset", new { id = vm.Id }, vm);
        }
Exemplo n.º 2
0
        public IHttpActionResult PutAsset(int id, AssetViewModel vm)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            if (id != vm.Id)
            {
                return BadRequest();
            }

            try
            {
                _inventory.MergeAsset(vm.Id, vm.SerialNumber, vm.Description);
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!AssetExists(id))
                {
                    return NotFound();
                }
                else
                {
                    throw;
                }
            }

            return StatusCode(HttpStatusCode.NoContent);
        }