Пример #1
0
        public IActionResult Patch([FromODataUri] int paymentTypeId, [FromBody] Delta <PaymentTypeDto> paymentTypeDelta)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(BadRequest(ModelState));
                }

                if (!_paymentTypeRepository.PaymentTypeExists(paymentTypeId))
                {
                    return(NotFound());
                }

                var paymentTypeToPatch = Mapper.Map <Delta <PaymentType> >(paymentTypeDelta);

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

                if (!TryValidateModel(paymentTypeToPatch))
                {
                    return(BadRequest());
                }

                var userId  = User.FindFirstValue(ClaimTypes.NameIdentifier);
                var profile = _accountRepository.GetUserProfile(userId);
                if (!_paymentTypeRepository.PartialUpdatePaymentType(paymentTypeId, paymentTypeToPatch, profile.UserProfileId))
                {
                    return(StatusCode(500, "A problem happened while handling your request."));
                }

                return(NoContent());
            }
            catch (Exception ex)
            {
                _logger.LogError($"Failed in Patch /PaymentTypes(paymentTypeId): {ex}");
                return(StatusCode(500, "A problem happened while handling your request."));
            }
        }