/// <summary>
 /// Get a list of matter types that match the search criteria
 /// </summary>
 /// <param name="oHostSecurityToken">HostSecurityToken obtained when security provider of IWS is called</param>
 /// <param name="collectionRequest">The collection request.</param>
 /// <param name="criteria">The criteria.</param>
 /// <returns></returns>
 public MatterTypeSearchReturnValue MatterTypeSearch(HostSecurityToken oHostSecurityToken, CollectionRequest collectionRequest,
                                     MatterTypeSearchCriteria criteria)
 {
     MatterTypeSearchReturnValue returnValue = null;
     if (Functions.ValidateIWSToken(oHostSecurityToken))
     {
         oMatterService = new MatterService();
         returnValue = oMatterService.MatterTypeSearch(Functions.GetLogonIdFromToken(oHostSecurityToken), collectionRequest, criteria);
     }
     else
     {
         returnValue = new MatterTypeSearchReturnValue();
         returnValue.Success = false;
         returnValue.Message = "Invalid Token";
     }
     return returnValue;
 }
        /// <summary>
        /// Get a list of matter types that match the search criteria
        /// </summary>
        /// <param name="logonId">The logon id.</param>
        /// <param name="collectionRequest">The collection request.</param>
        /// <param name="criteria">The criteria.</param>
        /// <returns></returns>
        public MatterTypeSearchReturnValue MatterTypeSearch(Guid logonId, CollectionRequest collectionRequest,
                                            MatterTypeSearchCriteria criteria)
        {
            MatterTypeSearchReturnValue returnValue = new MatterTypeSearchReturnValue();

            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:
                        case DataConstants.UserType.Client:
                        case DataConstants.UserType.ThirdParty:
                            // Can do everything
                            break;
                        default:
                            throw new Exception("Access denied");
                    }

                    // Create a data list creator for a list of matters
                    DataListCreator<MatterTypeSearchItem> dataListCreator = new DataListCreator<MatterTypeSearchItem>();

                    // Declare an inline event (annonymous delegate) to read the
                    // dataset if it is required
                    dataListCreator.ReadDataSet += delegate(object Sender, ReadDataSetEventArgs e)
                    {
                        e.DataSet = SrvMatterLookup.GetMatterTypes(criteria.ClientTypeId);
                    };

                    // Create the data list
                    returnValue.MatterTypes = dataListCreator.Create(logonId,
                        // Give the query a name so it can be cached
                        "MatterTypes",
                        // 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", "MatterTypeID"),
                            new ImportMapping("Description", "MatterTypeDesc"),
                            }
                        );
                }
                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>
        /// Gets the matter types.
        /// </summary>
        private void GetMatterTypes()
        {
            MatterServiceClient matterService = null;
            try
            {
                CollectionRequest collectionRequest = new CollectionRequest();

                MatterTypeSearchCriteria criteria = new MatterTypeSearchCriteria();
                criteria.ClientTypeId = (int)ViewState[ClientType];

                matterService = new MatterServiceClient();
                MatterTypeSearchReturnValue returnValue = matterService.MatterTypeSearch(_logonSettings.LogonId,
                                            collectionRequest, criteria);

                if (returnValue.Success)
                {
                    _ddlMatterType.DataSource = returnValue.MatterTypes.Rows;
                    _ddlMatterType.DataTextField = "Description";
                    _ddlMatterType.DataValueField = "Id";
                    _ddlMatterType.DataBind();
                }
                else
                {
                    throw new Exception(returnValue.Message);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                if (matterService != null)
                {
                    if (matterService.State != System.ServiceModel.CommunicationState.Faulted)
                        matterService.Close();
                }
            }
        }