コード例 #1
0
        // GET: ProductTypes/Details/5
        public async Task <ActionResult> Details(int id)
        {
            var productType = await _productTypeRepository.GetByIdAsync(id);

            if (productType == null)
            {
                return(HttpNotFound());
            }
            return(View(productType));
        }
コード例 #2
0
ファイル: InsuranceController.cs プロジェクト: pnobbe/cb
        public async Task <IActionResult> CalculateInsuranceForProductAsync([FromBody] ProductDto input)
        {
            // Map.
            var product = _mapper.Map <Product>(input);

            // Act.
            try
            {
                var productType = await _productTypeRepository.GetByIdAsync(product.ProductTypeId);

                InsuredProduct insuredProduct = new()
                {
                    ProductId               = product.Id,
                    ProductTypeName         = productType.Name,
                    ProductTypeHasInsurance = productType.CanBeInsured,
                    ProductTypeSurcharge    = productType.Surcharge,
                    SalesPrice              = product.SalesPrice,
                };

                // Map.
                var output = _mapper.Map <InsuredProductDto>(insuredProduct);

                // Return.
                return(Ok(output));
            }
            catch (ArgumentException e)
            {
                var message = string.Format("Unable to calculate insurance, {0}", e.Message);
                // Log
                _logger.LogError(message);

                // Return.
                return(NotFound(message));
            }
        }
コード例 #3
0
        public async Task <IActionResult> SetSurcharge(int id, [FromBody] float input)
        {
            // Act.
            var productType = await _productTypeRepository.GetByIdAsync(id);

            productType.Surcharge = input;

            await _productTypeRepository.UpdateAsync(productType);

            // Return.
            return(NoContent());
        }
コード例 #4
0
        public async Task <ActionResult <ProductType> > GetProductById(int id)
        {
            _logger.Log(LogLevel.Information, "{id}" + " " + id.ToString());

            var productTypeId = await _repo.GetByIdAsync(id);

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

            return(Ok(productTypeId));
        }
コード例 #5
0
        public async Task <ActionResult <ProductType> > GetById(int id)
        {
            try
            {
                var type = await _typeRepository.GetByIdAsync(id);

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

                return(Ok(type));
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }
コード例 #6
0
        public async Task <ProductTypeDTO> LoadDataAsync(string id)
        {
            var result = await _productTypeRepository.GetByIdAsync(id);

            return(_mapper.Map <ProductTypeDTO>(result));
        }