コード例 #1
0
        public async Task <IActionResult> GetById(Guid id)
        {
            WorkItemSubCategory workItemSubCategory = await _repository.GetByIdAsync(id);

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

            return(Ok(_mapper.Map(workItemSubCategory)));
        }
コード例 #2
0
        public async Task <IActionResult> Post(WorkItemSubCategoryRequest request)
        {
            try
            {
                WorkItemSubCategory workItemSubCategory = _mapper.Map(request);

                workItemSubCategory = await _repository.AddAsync(workItemSubCategory);

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

            catch (DataStoreException e)
            {
                _logger.LogError(e.Message, e, request);
                return(StatusCode(StatusCodes.Status500InternalServerError, e.Message));
            }
        }
コード例 #3
0
        public async Task <IActionResult> Delete(Guid id)
        {
            try
            {
                WorkItemSubCategory workItemSubCategory = await _repository.GetByIdAsync(id);

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

                await _repository.DeleteAsync(workItemSubCategory);

                return(Ok(id));
            }

            catch (DataStoreException e)
            {
                _logger.LogError(e.Message, e, id);
                return(StatusCode(StatusCodes.Status500InternalServerError, e.Message));
            }
        }
コード例 #4
0
        public async Task <IActionResult> Put(Guid id, WorkItemSubCategoryRequest request)
        {
            try
            {
                WorkItemSubCategory workItemSubCategory = await _repository.GetByIdAsync(id);

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

                _mapper.Map(workItemSubCategory, request);

                await _repository.UpdateAsync(workItemSubCategory);

                return(Ok());
            }

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