コード例 #1
0
        public IActionResult UpdateCustomerType(int customerTypeId, [FromBody] CustomerTypeForUpdateDto payload)
        {
            if (payload.Label == payload.Description)
            {
                ModelState.AddModelError("Description", "Label must be different from description.");
            }

            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            if (!_customerTypeService.IsCustomerTypeExist(customerTypeId))
            {
                return(NotFound());
            }

            CustomerType newCustomerType = new CustomerType(customerTypeId, payload.Label, payload.Description);

            _customerTypeService.UpdateCustomerType(newCustomerType);

            return(CreatedAtRoute(
                       "GetCustomerTypeById",
                       new { id = customerTypeId },
                       _mapper.Map <CustomerTypeDto>(newCustomerType)));
        }