public IActionResult Post([FromBody] AddressTypeDto addressTypeDto) { try { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } 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 createdAddressType = _addressTypeRepository.CreateAddressType(addressType, profile.UserProfileId); if (createdAddressType == null) { return(StatusCode(500, "A problem happened while handling your request.")); } var createdAddressTypeToReturn = Mapper.Map <AddressTypeDto>(createdAddressType); return(Created(createdAddressTypeToReturn)); } catch (Exception ex) { _logger.LogError($"Failed in Post /AddressTypes: {ex}"); return(StatusCode(500, "A problem happened while handling your request.")); } }
public AddressTypeDto CreateAddressType(AddressTypeDto addressTypeDto) { return(_addressTypeRepository.CreateAddressType(addressTypeDto)); }