예제 #1
0
        public IActionResult Create([FromBody] Requests.AssetDto assetDto)
        {
            // map dto to entity
            var asset = _mapper.Map <Asset>(assetDto);

            try
            {
                // save
                _assetService.Create(asset);
                return(Ok());
            }
            catch (AppException ex)
            {
                // return error message if there was an exception
                return(BadRequest(ex.Message));
            }
        }
예제 #2
0
        public IActionResult Update(Guid id, [FromBody] Requests.AssetDto assetDto)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            // map dto to entity and set id
            var asset = _mapper.Map <Asset>(assetDto);

            asset.Id = id;

            try
            {
                // save
                _assetService.Update(asset);
                return(Ok());
            }
            catch (AppException ex)
            {
                // return error message if there was an exception
                return(BadRequest(ex.Message));
            }
        }