예제 #1
0
        public async Task <IActionResult> Post(BinRequest request)
        {
            try
            {
                Bin bin = _mapper.Map(request);

                bin = await _repository.AddAsync(bin);

                return(CreatedAtAction(nameof(GetById), new { id = bin.Id }, _mapper.Map(bin)));
            }

            catch (DataStoreException e)
            {
                _logger.LogError(e.Message, e, request);
                return(StatusCode(StatusCodes.Status500InternalServerError, e.Message));
            }
        }
예제 #2
0
        public async Task <IActionResult> Put(Guid id, BinRequest request)
        {
            try
            {
                Bin bin = await _repository.GetByIdAsync(id);

                if (bin == null)
                {
                    return(NotFound());
                }

                _mapper.Map(bin, request);

                await _repository.UpdateAsync(bin);

                return(Ok());
            }

            catch (DataStoreException e)
            {
                _logger.LogError(e.Message, e, request);
                return(StatusCode(StatusCodes.Status500InternalServerError, e.Message));
            }
        }