public IActionResult Get([FromODataUri] int addressTypeId)
        {
            try
            {
                var addressType = _addressTypeRepository.GetAddressType(addressTypeId);
                if (addressType == null)
                {
                    return(NotFound());
                }

                var result = Mapper.Map <AddressTypeDto>(addressType);
                return(Ok(result));
            }
            catch (Exception ex)
            {
                _logger.LogError($"Failed in Get /AddressTypes(addressTypeId): {ex}");
                return(BadRequest());
            }
        }
Exemple #2
0
        public IActionResult AddAddressType(AddressTypeViewModel addresstypeVm)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            _addTypeRepo.AddAddressType(addresstypeVm.ReverseMap());

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

            AddressTypeViewModel addTypeVM = new AddressTypeViewModel();

            addTypeVM.MapSingleAddressType(addressType);

            CreatedAtRouteResult response = CreatedAtRoute("GetAddressType", new { controller = "AddressTypes", id = addTypeVM.ID }, addTypeVM);

            return(response);
        }