Ejemplo n.º 1
0
        public IActionResult Put([FromODataUri] int addressTypeId, [FromBody] AddressTypeDto addressTypeDto)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(BadRequest(ModelState));
                }

                if (!_addressTypeRepository.AddressTypeExists(addressTypeId))
                {
                    return(NotFound());
                }

                var addressType = Mapper.Map <AddressType>(addressTypeDto);
                if (_addressTypeRepository.AddressTypeExists(addressType))
                {
                    return(StatusCode(500, "AddressType already exists."));
                }

                var userId             = User.FindFirstValue(ClaimTypes.NameIdentifier);
                var profile            = _accountRepository.GetUserProfile(userId);
                var updatedAddressType = _addressTypeRepository.UpdateAddressType(addressTypeId, addressType, profile.UserProfileId);

                if (updatedAddressType == null)
                {
                    return(StatusCode(500, "A problem happened while handling your request."));
                }

                var updatedAddressTypeToReturn = Mapper.Map <AddressTypeDto>(updatedAddressType);
                return(Created(updatedAddressTypeToReturn));
            }
            catch (Exception ex)
            {
                _logger.LogError($"Failed in Put /AddressTypes(addressTypeId): {ex}");
                return(StatusCode(500, "A problem happened while handling your request."));
            }
        }
Ejemplo n.º 2
0
        public IActionResult UpdateAddressType(AddressTypeViewModel addressType)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var addressT = _addTypeRepo.GetAddressType(addressType.ID);

            if (addressT == null)
            {
                return(NotFound());
            }
            else
            {
                var newAddressType = addressType.ReverseMap();
                _addTypeRepo.UpdateAddressType(newAddressType);

                var AddressTVm = new AddressTypeViewModel(newAddressType);

                return(new OkObjectResult(AddressTVm));
            }
        }