Пример #1
0
        public ActionResult <Result <GetComponentDto> > Post([FromBody] CreateComponentDto createComponentDto)
        {
            var componentToCreate = new Component
            {
                QuantityType = createComponentDto.QuantityType,
                UnitPrice    = createComponentDto.UnitPrice,
                Description  = createComponentDto.Description
            };

            var resultFromRepository = componentRepository.Create(componentToCreate);

            return(CreatedAtAction(nameof(Get), new { id = resultFromRepository.Value.Id }, new Result <GetComponentDto>
            {
                IsSuccess = resultFromRepository.IsSuccess,
                Message = resultFromRepository.Message,
                Value = resultFromRepository.Value != null
        ? new GetComponentDto
                {
                    Id = resultFromRepository.Value.Id,
                    QuantityType = resultFromRepository.Value.QuantityType,
                    UnitPrice = resultFromRepository.Value.UnitPrice,
                    Description = resultFromRepository.Value.Description
                }
        : null
            }));
        }