Example #1
0
        /// <summary>
        /// Gets the address.
        /// </summary>
        /// <param name="memId">The mem id.</param>
        /// <param name="orgId">The org id.</param>
        /// <returns></returns>
        private string GetAddress(Guid memId, Guid orgId)
        {
            string addressLine1 = string.Empty;
            ClientServiceClient clientService = null;

            try
            {
                CollectionRequest     collectionRequest = new CollectionRequest();
                AddressSearchCriteria criteria          = new AddressSearchCriteria();
                criteria.MemberId       = memId;
                criteria.OrganisationId = orgId;

                clientService = new ClientServiceClient();
                AddressSearchReturnValue returnValue = clientService.GetClientAddresses(_logonSettings.LogonId,
                                                                                        collectionRequest,
                                                                                        criteria);

                if (returnValue.Success)
                {
                    if (returnValue.Addresses.Rows.Length > 0)
                    {
                        addressLine1 = returnValue.Addresses.Rows[0].Line1;
                    }
                }
                else
                {
                    throw new Exception(returnValue.Message);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                if (clientService != null)
                {
                    if (clientService.State != System.ServiceModel.CommunicationState.Faulted)
                    {
                        clientService.Close();
                    }
                }
            }

            return(addressLine1);
        }
Example #2
0
        /// <summary>
        /// Get the address for the specified contact
        /// </summary>
        /// <param name="oHostSecurityToken"></param>
        /// <param name="collectionRequest"></param>
        /// <param name="criteria"></param>
        /// <returns></returns>
        public AddressSearchReturnValue GetContactAddresses(HostSecurityToken oHostSecurityToken, CollectionRequest collectionRequest,
                                                            AddressSearchCriteria criteria)
        {
            AddressSearchReturnValue returnValue = null;

            if (Functions.ValidateIWSToken(oHostSecurityToken))
            {
                oContactService = new ContactService();
                returnValue     = oContactService.GetContactAddresses(Functions.GetLogonIdFromToken(oHostSecurityToken), collectionRequest, criteria);
            }
            else
            {
                returnValue         = new AddressSearchReturnValue();
                returnValue.Success = false;
                returnValue.Message = "Invalid Token";
            }
            return(returnValue);
        }
Example #3
0
        /// <summary>
        /// Loads the client details.
        /// </summary>
        private void LoadAddressDetails()
        {
            ClientServiceClient serviceClient = null;

            try
            {
                serviceClient             = new ClientServiceClient();
                _addressSearchReturnValue = new AddressSearchReturnValue();
                CollectionRequest     collectionRequest = new CollectionRequest();
                AddressSearchCriteria searchCriteria    = new AddressSearchCriteria();
                searchCriteria.MemberId       = _memId;
                searchCriteria.OrganisationId = _orgId;
                _addressSearchReturnValue     = serviceClient.GetClientAddresses(_logonId, collectionRequest, searchCriteria);

                if (_addressSearchReturnValue.Success)
                {
                    GetAddressTypes();
                    DisplayAddressDetails();
                }
                else
                {
                    throw new Exception(_addressSearchReturnValue.Message);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                if (serviceClient != null)
                {
                    if (serviceClient.State != System.ServiceModel.CommunicationState.Faulted)
                    {
                        serviceClient.Close();
                    }
                }
            }
        }
        /// <summary>
        /// Loads the client details.
        /// </summary>
        private void LoadAddressDetails()
        {
            ClientServiceClient serviceClient = null;
            try
            {
                serviceClient = new ClientServiceClient();
                _addressSearchReturnValue = new AddressSearchReturnValue();
                CollectionRequest collectionRequest = new CollectionRequest();
                AddressSearchCriteria searchCriteria = new AddressSearchCriteria();
                searchCriteria.MemberId = _memId;
                searchCriteria.OrganisationId = _orgId;
                _addressSearchReturnValue = serviceClient.GetClientAddresses(_logonId, collectionRequest, searchCriteria);

                if (_addressSearchReturnValue.Success)
                {
                    GetAddressTypes();
                    DisplayAddressDetails();
                }
                else
                {
                    throw new Exception(_addressSearchReturnValue.Message);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                if (serviceClient != null)
                {
                    if (serviceClient.State != System.ServiceModel.CommunicationState.Faulted)
                        serviceClient.Close();
                }
            }
        }
        /// <summary>
        /// Get the address for the specified contact  
        /// </summary>
        /// <param name="logonId"></param>
        /// <param name="collectionRequest"></param>
        /// <param name="criteria"></param>
        /// <returns></returns>
        public AddressSearchReturnValue GetContactAddresses(Guid logonId, CollectionRequest collectionRequest,
                                        AddressSearchCriteria criteria)
        {
            AddressSearchReturnValue returnValue = new AddressSearchReturnValue();
            SrvAddress srvAddress;

            try
            {
                // Get the logged on user from the current logons and add their
                // ApplicationSettings the list of concurrent sessions.
                Host.LoadLoggedOnUser(logonId);

                try
                {
                    Functions.RestrictRekoopIntegrationUser(UserInformation.Instance.DbUid);
                    switch (UserInformation.Instance.UserType)
                    {
                        case DataConstants.UserType.Staff:
                            // Can do everything
                            break;
                        case DataConstants.UserType.Client:
                        case DataConstants.UserType.ThirdParty:
                            if (!ApplicationSettings.Instance.IsUser(criteria.MemberId, criteria.OrganisationId))
                                throw new Exception("Access denied");
                            break;
                        default:
                            throw new Exception("Access denied");
                    }

                    DataListCreator<Address> dataListCreator = new DataListCreator<Address>();

                    // Declare an inline event (annonymous delegate) to read the
                    // dataset if it is required
                    dataListCreator.ReadDataSet += delegate(object Sender, ReadDataSetEventArgs e)
                    {
                        if (criteria.MemberId != DataConstants.DummyGuid)
                        {
                            e.DataSet = SrvAddressLookup.GetMemberAddresses(criteria.MemberId);
                        }
                        else if (criteria.OrganisationId != DataConstants.DummyGuid)
                        {
                            e.DataSet = SrvAddressLookup.GetOrganisationAddresses(criteria.OrganisationId);
                        }
                    };

                    // Create the data list
                    returnValue.Addresses = dataListCreator.Create(logonId,
                        // Give the query a name so it can be cached
                        "ClientAddresses",
                        // Tell it the query criteria used so if the cache is accessed
                        // again it knows if it is the same query
                        criteria.ToString(),
                        collectionRequest,
                        // Import mappings to map the dataset row fields to the data
                        // list entity properties
                        new ImportMapping[] {
                            new ImportMapping("Id", "AddressId"),
                            new ImportMapping("TypeId", "AddressTypeID"),
                            new ImportMapping("Line1", "AddressLine1"),
                            new ImportMapping("Line2", "AddressLine2"),
                            new ImportMapping("Line3", "AddressLine3"),
                            new ImportMapping("Town", "AddressTown"),
                            new ImportMapping("County", "AddressCounty"),
                            new ImportMapping("PostCode", "AddressPostCode"),
                            new ImportMapping("DXTown", "AddressDXTown"),
                            new ImportMapping("DXNumber", "AddressDX"),
                            new ImportMapping("Country", "AddressCountry"),
                            new ImportMapping("IsMailingAddress", "AddressMailingAddress"),
                            new ImportMapping("IsBillingAddress", "AddressBillingAddress"),
                            new ImportMapping("Comment", "AddressComment"),
                            new ImportMapping("OrganisationName", "AddressOrgName"),
                            new ImportMapping("Department", "AddressDept"),
                            new ImportMapping("PostBox", "AddressPoBox"),
                            new ImportMapping("SubBuilding", "AddressSubBldg"),
                            new ImportMapping("StreetNumber", "AddressStreetNo"),
                            new ImportMapping("HouseName", "AddressHouseName"),
                            new ImportMapping("DependantLocality", "AddressDepLocality"),
                            new ImportMapping("LastVerified", "AddressLastVerified"),
                            }
                        );

                    int intCtr;
                    foreach (Address address in returnValue.Addresses.Rows)
                    {
                        srvAddress = new SrvAddress();
                        srvAddress.MemberId = criteria.MemberId;
                        srvAddress.OrganisationId = criteria.OrganisationId;
                        srvAddress.Load(address.Id);
                        address.AdditionalAddressElements = new List<AdditionalAddressElement>();
                        for (intCtr = 0; intCtr < srvAddress.AdditionalInfoElements.Count; intCtr++)
                        {
                            AdditionalAddressElement additionalAddressElement = new AdditionalAddressElement();
                            additionalAddressElement.ElementComment = srvAddress.AdditionalInfoElements[intCtr].AddressElComment;
                            additionalAddressElement.ElementText = srvAddress.AdditionalInfoElements[intCtr].AddressElementText;
                            additionalAddressElement.TypeId = srvAddress.AdditionalInfoElements[intCtr].AddressElTypeId;
                            address.AdditionalAddressElements.Add(additionalAddressElement);
                        }
                    }
                }
                finally
                {
                    // Remove the logged on user's ApplicationSettings from the
                    // list of concurrent sessions
                    Host.UnloadLoggedOnUser();
                }
            }
            catch (System.Data.SqlClient.SqlException)
            {
                returnValue.Success = false;
                returnValue.Message = Functions.SQLErrorMessage;
            }
            catch (Exception Ex)
            {
                returnValue.Success = false;
                returnValue.Message = Ex.Message;
            }

            return returnValue;
        }
        /// <summary>
        /// Displays the address details for the selected address type.
        /// </summary>
        private void DisplayContactAddressDetails()
        {
            try
            {
                AddressSearchReturnValue addressSearchReturnValue = new AddressSearchReturnValue();
                CollectionRequest collectionRequest = new CollectionRequest();
                AddressSearchCriteria searchCriteria = new AddressSearchCriteria();
                searchCriteria.MemberId = _memberId;
                searchCriteria.OrganisationId = _organisationId;

                ContactServiceClient serviceClient = new ContactServiceClient();
                addressSearchReturnValue = serviceClient.GetContactAddresses(_logonSettings.LogonId, collectionRequest, searchCriteria);

                List<Address> contactAddresses = null;
                Address currentAddress = null;
                if (!IsPostBack)
                {
                    GetContactAddressTypes();
                    //Store the addresses in a list so that we can add items if necessary
                    contactAddresses = new List<Address>();
                    foreach (Address address in addressSearchReturnValue.Addresses.Rows)
                    {
                        contactAddresses.Add(address);
                    }
                    Session[SessionName.ClientAddresses] = contactAddresses;
                }
                else
                {
                    contactAddresses = (List<Address>)Session[SessionName.ClientAddresses];
                }

                //Get the current selected address type and display the address
                foreach (Address address in contactAddresses)
                {
                    if (address.TypeId == 1)
                    {
                        Session[SessionName.ContactDetails] = address.AdditionalAddressElements;
                    }

                    if (address.TypeId == Convert.ToInt32(_ddlAddressType.SelectedValue))
                    {
                        currentAddress = address;
                        break;
                    }
                }
                //If an address exists then display it..
                if (currentAddress != null)
                {
                    List<string> updatedAddresses = (List<string>)ViewState[UpdatedAddresses];
                    _ucAddress.Address = currentAddress;
                    _ucAddress.IsDataChanged = updatedAddresses.Contains(currentAddress.TypeId.ToString());
                    _ucAddress.DataBind();
                }
                else
                {
                    //No address exists for the current type, so create a new one
                    currentAddress = new Address();
                    currentAddress.LastVerified = DataConstants.BlankDate;
                    currentAddress.TypeId = Convert.ToInt32(_ddlAddressType.SelectedValue);
                    contactAddresses.Add(currentAddress);
                    _ucAddress.Address = currentAddress;
                    _ucAddress.IsDataChanged = false;
                    _ucAddress.DataBind();
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        /// <summary>
        /// Saves the addresses.
        /// </summary>
        private void SaveAddresses()
        {
            ContactServiceClient contactService = null;
            ClientServiceClient clientService = null;
            try
            {
                CheckForModifiedAddress();
                List<string> updatedAddresses = (List<string>)ViewState[UpdatedAddresses];
                //Check if any of the addresses have been modified
                if (updatedAddresses.Count > 0)
                {
                    contactService = new ContactServiceClient();
                    List<Address> clientAddresses = (List<Address>)Session[SessionName.ClientAddresses];
                    foreach (string addressType in updatedAddresses)
                    {
                        foreach (Address address in clientAddresses)
                        {
                            if (address.TypeId.ToString() == addressType)
                            {

                                if (_logonSettings.UserType == (int)DataConstants.UserType.ThirdParty && Request.QueryString["mydetails"] == "true")
                                {
                                    address.MemberId = _logonSettings.MemberId;
                                    address.OrganisationId = _logonSettings.OrganisationId;
                                }
                                else
                                {
                                    address.MemberId = (Guid)Session[SessionName.MemberId];
                                    address.OrganisationId = (Guid)Session[SessionName.OrganisationId];
                                }

                                AddressReturnValue returnValue = contactService.SaveAddress(_logonSettings.LogonId, address);
                                if (!returnValue.Success)
                                {
                                    _lblMessage.CssClass = "errorMessage";
                                    _lblMessage.Text = returnValue.Message;
                                }
                                break;
                            }
                        }
                    }
                    updatedAddresses.Clear();
                    //Reload the addresses
                    clientService = new ClientServiceClient();
                    AddressSearchCriteria searchCriteria = new AddressSearchCriteria();
                    searchCriteria.MemberId = _memberId;
                    searchCriteria.OrganisationId = _organisationId;
                    CollectionRequest collectionRequest = new CollectionRequest();
                    collectionRequest.ForceRefresh = true;

                    if (Request.QueryString["mydetails"] == "true" && _logonSettings.UserType == (int)DataConstants.UserType.ThirdParty)
                    {
                        AddressSearchReturnValue addressSearchReturnValue = new AddressSearchReturnValue();
                        ContactServiceClient serviceClient = new ContactServiceClient();
                        addressSearchReturnValue = serviceClient.GetContactAddresses(_logonSettings.LogonId, collectionRequest, searchCriteria);
                        clientAddresses.Clear();
                        //Store the addresses in a list so that we can add items if necessary
                        foreach (Address address in addressSearchReturnValue.Addresses.Rows)
                        {
                            clientAddresses.Add(address);
                        }

                    }
                    else
                    {
                        AddressSearchReturnValue addresses = clientService.GetClientAddresses(_logonSettings.LogonId,
                                                                                            collectionRequest,
                                                                                            searchCriteria);
                        clientAddresses.Clear();
                        //Store the addresses in a list so that we can add items if necessary
                        foreach (Address address in addresses.Addresses.Rows)
                        {
                            clientAddresses.Add(address);
                        }
                    }

                    if (Request.QueryString["mydetails"] == "true" && _logonSettings.UserType == (int)DataConstants.UserType.ThirdParty)
                    {
                        DisplayContactAddressDetails();
                    }
                    else
                    {
                        DisplayAddressDetails();
                    }
                }
            }
            catch (System.ServiceModel.EndpointNotFoundException)
            {
                _lblMessage.Text = DataConstants.WSEndPointErrorMessage;
                _lblMessage.CssClass = "errorMessage";
            }
            catch (Exception ex)
            {
                _lblMessage.CssClass = "errorMessage";
                _lblMessage.Text = ex.Message;
            }
            finally
            {
                if (contactService != null)
                {
                    if (contactService.State != System.ServiceModel.CommunicationState.Faulted)
                        contactService.Close();
                }

                if (clientService != null)
                {
                    if (clientService.State != System.ServiceModel.CommunicationState.Faulted)
                        clientService.Close();
                }
            }
        }
 /// <summary>
 /// Get the address for the specified contact  
 /// </summary>
 /// <param name="oHostSecurityToken"></param>
 /// <param name="collectionRequest"></param>
 /// <param name="criteria"></param>
 /// <returns></returns>
 public AddressSearchReturnValue GetContactAddresses(HostSecurityToken oHostSecurityToken, CollectionRequest collectionRequest,
                                 AddressSearchCriteria criteria)
 {
     AddressSearchReturnValue returnValue = null;
     if (Functions.ValidateIWSToken(oHostSecurityToken))
     {
         oContactService = new ContactService();
         returnValue = oContactService.GetContactAddresses(Functions.GetLogonIdFromToken(oHostSecurityToken), collectionRequest, criteria);
     }
     else
     {
         returnValue = new AddressSearchReturnValue();
         returnValue.Success = false;
         returnValue.Message = "Invalid Token";
     }
     return returnValue;
 }