/// <summary>
        /// This method updates the Person / Organisation information
        /// using contact service .
        /// </summary>
        /// <param name="logonId">User logon ID</param>
        /// <param name="person">Person information</param>
        /// <param name="contactType">Individual / Organisation</param>
        /// <param name="organisation">Organisation Information</param>
        /// <returns>Return Value</returns>
        public ReturnValue UpdateGeneralContact(Guid logonId, Person person, IRISLegal.IlbCommon.ContactType contactType, Organisation organisation)
        {
            ReturnValue returnValue = new ReturnValue();

            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
                        case DataConstants.UserType.ThirdParty:
                            switch (contactType)
                            {
                                case IRISLegal.IlbCommon.ContactType.Individual:
                                    if (!ApplicationSettings.Instance.IsUser(person.MemberId, DataConstants.DummyGuid))
                                        throw new Exception("Access denied");
                                    break;
                                case IRISLegal.IlbCommon.ContactType.Organisation:
                                    if (!ApplicationSettings.Instance.IsUser(DataConstants.DummyGuid, organisation.OrganisationId))
                                        throw new Exception("Access denied");
                                    break;
                                default:
                                    throw new Exception("Invalid contact type");
                            }

                            break;
                        case DataConstants.UserType.Client:
                            switch (contactType)
                            {
                                case IRISLegal.IlbCommon.ContactType.Individual:
                                    if (!ApplicationSettings.Instance.IsUser(person.MemberId, DataConstants.DummyGuid))
                                        throw new Exception("Access denied");
                                    break;
                                case IRISLegal.IlbCommon.ContactType.Organisation:
                                    if (!ApplicationSettings.Instance.IsUser(DataConstants.DummyGuid, organisation.OrganisationId))
                                        throw new Exception("Access denied");
                                    break;
                                default:
                                    throw new Exception("Invalid contact type");
                            }
                            break;
                        default:
                            throw new Exception("Access denied");
                    }

                    SrvServiceContact serviceContactService = new SrvServiceContact();
                    SrvContact contactService = new SrvContact();

                    string errorMessage;
                    string errorMessageWarning;

                    contactService.ContactType = contactType;
                    contactService.Load(person.MemberId);

                    if (!contactService.ValidateId(out errorMessage, out errorMessageWarning))
                    {
                        serviceContactService.Id = person.MemberId;
                        serviceContactService.Load();

                        serviceContactService.Person.ForeName = person.ForeName;
                        serviceContactService.Person.MaritalId = person.MaritalStatusId;
                        serviceContactService.Person.PersonArmedForcesNo = person.ArmedForcesNo;
                        serviceContactService.Person.PersonBirthName = person.BirthName;
                        serviceContactService.Person.PersonDisability = person.DisabilityId;
                        serviceContactService.Person.PersonDOB = person.DOB;
                        serviceContactService.Person.PersonDOD = person.DOD;
                        serviceContactService.Person.PersonEthnicityId = person.EthnicityId;
                        serviceContactService.Person.PersonNINo = person.NINo;
                        serviceContactService.Person.PersonOccupation = person.Occupation;
                        serviceContactService.Person.PersonPlaceOfBirth = person.PlaceOfBirth;
                        serviceContactService.Person.PersonPreviousName = person.PreviousName;
                        serviceContactService.Person.PersonSalEnv = person.SalutationEnvelope;
                        serviceContactService.Person.PersonSalLet = person.SalutationLettterFriendly;
                        serviceContactService.Person.PersonSalletForm = person.SalutationLettterFormal;
                        serviceContactService.Person.PersonSalutationlettterInformal = person.SalutationLettterInformal;
                        serviceContactService.Person.Sex = person.Sex;
                        serviceContactService.Person.Surname = person.Surname;
                        serviceContactService.Person.Title = person.Title;

                        returnValue.Success = serviceContactService.Save(out errorMessage);
                        returnValue.Message = errorMessage;
                    }
                    else
                    {

                        if (contactService.ContactType == IRISLegal.IlbCommon.ContactType.Individual)
                        {

                            //Person Information for Individual contact

                            contactService.Person.ForeName = person.ForeName;
                            contactService.Person.MaritalId = person.MaritalStatusId;
                            contactService.Person.PersonArmedForcesNo = person.ArmedForcesNo;
                            contactService.Person.PersonBirthName = person.BirthName;
                            contactService.Person.PersonDisability = person.DisabilityId;
                            contactService.Person.PersonDOB = person.DOB;
                            contactService.Person.PersonDOD = person.DOD;
                            contactService.Person.PersonEthnicityId = person.EthnicityId;
                            contactService.Person.PersonNINo = person.NINo;
                            contactService.Person.PersonOccupation = person.Occupation;
                            contactService.Person.PersonPlaceOfBirth = person.PlaceOfBirth;
                            contactService.Person.PersonPreviousName = person.PreviousName;
                            contactService.Person.PersonSalEnv = person.SalutationEnvelope;
                            contactService.Person.PersonSalLet = person.SalutationLettterFriendly;
                            contactService.Person.PersonSalletForm = person.SalutationLettterFormal;
                            contactService.Person.PersonSalutationlettterInformal = person.SalutationLettterInformal;
                            contactService.Person.Sex = person.Sex;
                            contactService.Person.Surname = person.Surname;
                            contactService.Person.Title = person.Title;
                        }
                        else
                        {
                            contactService.Load(organisation.OrganisationId);
                            contactService.Organisation.IndustryId = organisation.IndustryId;
                            contactService.Organisation.Name = organisation.Name;
                            contactService.Organisation.RegisteredName = organisation.RegisteredName;
                            contactService.Organisation.RegisteredNumber = organisation.RegisteredNo;
                            contactService.Organisation.SubTypesId = organisation.SubTypeId;
                            contactService.Organisation.VATNumber = organisation.VATNo;
                        }

                        returnValue.Success = contactService.Save(out errorMessage);
                        returnValue.Message = errorMessage;
                    }
                }
                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>
        /// This method adds the Person, Address and Additional Address information
        /// using contact service to create a general contact.
        /// </summary>
        /// <param name="logonId">User logon ID</param>
        /// <param name="contactAddress">Address information for contact</param>
        /// <param name="person">Person information</param>
        /// <param name="additionalElement">Additional Element</param>
        /// <param name="contactType">Individual / Organisation</param>
        /// <param name="organisation">Organisation Information</param>
        /// <param name="conflictNoteSummary">The conflict note summary.</param>
        /// <param name="conflictNoteContent">Content of the conflict note.</param>
        /// <returns>Return Value</returns>
        public ReturnValue SaveGeneralContact(Guid logonId,
                                              Address contactAddress,
                                              Person person,
                                              AdditionalAddressElement[] additionalElement,
                                              IRISLegal.IlbCommon.ContactType contactType,
                                              Organisation organisation,
                                              string conflictNoteSummary,
                                              string conflictNoteContent)
        {
            ReturnValue returnValue = new ReturnValue();

            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(additionalElement[0].MemberId, additionalElement[0].OrganisationId))
                                throw new Exception("Access denied");
                            break;
                        default:
                            throw new Exception("Access denied");
                    }

                    SrvContact contactService = new SrvContact();
                    SrvAddress srvAddress = new SrvAddress();

                    srvAddress.AddressTypeId = Convert.ToInt32(DataConstants.SystemAddressTypes.Main);
                    srvAddress.AddressStreetNumber = contactAddress.StreetNumber;
                    srvAddress.AddressPostCode = contactAddress.PostCode;
                    srvAddress.AddressHouseName = contactAddress.HouseName;
                    srvAddress.AddressLine1 = contactAddress.Line1;
                    srvAddress.AddressLine2 = contactAddress.Line2;
                    srvAddress.AddressLine3 = contactAddress.Line3;
                    srvAddress.AddressTown = contactAddress.Town;
                    srvAddress.AddressCounty = contactAddress.County;
                    srvAddress.AddressCountry = contactAddress.Country;
                    srvAddress.AddressDXTown = contactAddress.DXTown;
                    srvAddress.AddressDXNumber = contactAddress.DXNumber;
                    srvAddress.IsMailingAddress = contactAddress.IsMailingAddress;
                    srvAddress.IsBillingAddress = contactAddress.IsBillingAddress;

                    srvAddress.AddressOrgName = contactAddress.OrganisationName;
                    srvAddress.AddressComment = contactAddress.Comment;
                    srvAddress.AddressDepartment = contactAddress.Department;
                    srvAddress.AddressPostBox = contactAddress.PostBox;
                    srvAddress.AddressSubBuilding = contactAddress.SubBuilding;
                    srvAddress.AddressStreetNumber = contactAddress.StreetNumber;
                    srvAddress.AddressDependantLocality = contactAddress.DependantLocality;
                    srvAddress.AddressLastVerified = contactAddress.LastVerified;

                    // Save Additional Address Info to Address Object
                    if (additionalElement != null)
                    {
                        for (int i = 0; i <= 9; i++)
                        {
                            srvAddress.AdditionalInfoElements[i].AddressElementText = additionalElement[i].ElementText;
                        }
                    }

                    contactService.Addresses.Add(srvAddress);
                    contactService.ContactType = contactType;

                    if (contactService.ContactType == IRISLegal.IlbCommon.ContactType.Individual)
                    {
                        //Person Information for Individual contact
                        contactService.Person.Surname = person.Surname;
                        contactService.Person.ForeName = person.ForeName;
                        contactService.Person.Title = person.Title;
                    }
                    else
                    {
                        contactService.Organisation.Name = organisation.Name;
                    }

                    contactService.ConflictNoteSummary = conflictNoteSummary;
                    contactService.ConflictNoteContent = conflictNoteContent;

                    string errorMessage;

                    returnValue.Success = contactService.Save(out errorMessage);
                    returnValue.Message = errorMessage;
                }
                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>
 /// This method updates the Person / Organisation information
 /// using contact service .
 /// </summary>
 /// <param name="oHostSecurityToken">User logon ID</param>
 /// <param name="person">Person information</param>
 /// <param name="contactType">Individual / Organisation</param>
 /// <param name="organisation">Organisation Information</param>
 /// <returns>Return Value</returns>
 public ReturnValue UpdateGeneralContact(HostSecurityToken oHostSecurityToken, Person person, IRISLegal.IlbCommon.ContactType contactType, Organisation organisation)
 {
     ReturnValue returnValue = null;
     if (Functions.ValidateIWSToken(oHostSecurityToken))
     {
         oContactService = new ContactService();
         returnValue = oContactService.UpdateGeneralContact(Functions.GetLogonIdFromToken(oHostSecurityToken), person, contactType, organisation);
     }
     else
     {
         returnValue = new ReturnValue();
         returnValue.Success = false;
         returnValue.Message = "Invalid Token";
     }
     return returnValue;
 }
 /// <summary>
 /// This method adds the Person, Address and Additional Address information
 /// using contact service to create a general contact.
 /// </summary>
 /// <param name="logonId">User logon ID</param>
 /// <param name="contactAddress">Address information for contact</param>
 /// <param name="person">Person information</param>
 /// <param name="additionalElement">Additional Element</param>
 /// <param name="contactType">Individual / Organisation</param>
 /// <param name="organisation">Organisation Information</param>
 /// <param name="conflictNoteSummary">The conflict note summary.</param>
 /// <param name="conflictNoteContent">Content of the conflict note.</param>
 /// <returns>Return Value</returns>
 public ReturnValue SaveGeneralContact(HostSecurityToken oHostSecurityToken,
                                       Address contactAddress,
                                       Person person,
                                       AdditionalAddressElement[] additionalElement,
                                       IRISLegal.IlbCommon.ContactType contactType,
                                       Organisation organisation,
                                       string conflictNoteSummary,
                                       string conflictNoteContent)
 {
     ReturnValue returnValue = null;
     if (Functions.ValidateIWSToken(oHostSecurityToken))
     {
         oContactService = new ContactService();
         returnValue = oContactService.SaveGeneralContact(Functions.GetLogonIdFromToken(oHostSecurityToken), contactAddress, person, additionalElement, contactType, organisation,
             conflictNoteSummary, conflictNoteContent);
     }
     else
     {
         returnValue = new ReturnValue();
         returnValue.Success = false;
         returnValue.Message = "Invalid Token";
     }
     return returnValue;
 }
 public ConflictCheckStandardReturnValue ConflictCheck(HostSecurityToken oHostSecurityToken,
     CollectionRequest collectionRequest,
     IRISLegal.IlbCommon.ContactType clientType,
     Person person,
     Organisation organisation,
     Address addresses,
     List<AdditionalAddressElement> addressInformation,
     bool checkOnAllRoles)
 {
     ConflictCheckStandardReturnValue returnValue = null;
     if (Functions.ValidateIWSToken(oHostSecurityToken))
     {
         oClientService = new ClientService();
         returnValue = oClientService.ConflictCheck(Functions.GetLogonIdFromToken(oHostSecurityToken), collectionRequest,
            clientType, person, organisation, addresses, addressInformation, checkOnAllRoles);
     }
     else
     {
         returnValue = new ConflictCheckStandardReturnValue();
         returnValue.Success = false;
         returnValue.Message = "Invalid Token";
     }
     return returnValue;
 }
        public ConflictCheckStandardReturnValue ConflictCheck(Guid logonId,
            CollectionRequest collectionRequest,
            IRISLegal.IlbCommon.ContactType clientType,
            Person person,
            Organisation organisation,
            Address addresses,
            List<AdditionalAddressElement> addressInformation, 
            bool checkOnAllRoles)
        {
            ConflictCheckStandardReturnValue returnValue = new ConflictCheckStandardReturnValue();
            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:
                            throw new Exception("Access denied");
                        default:
                            throw new Exception("Access denied");
                    }

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

                    //Assign all control values to ConflictCheckFields
                    SrvConflictCheckFields conflictFields = new SrvConflictCheckFields();
                    SrvConflictCheck conflictCheck = new SrvConflictCheck();
                    conflictFields.ConflictCheckClientType = clientType;

                    if (person != null)
                    {
                        conflictFields.PersonSurname = person.Surname;
                        conflictFields.PersonName = person.ForeName;
                        conflictFields.PersonTitle = person.Title;
                    }
                    if (organisation != null)
                    {
                        conflictFields.OrgName = organisation.Name;
                    }
                    if (addresses != null)
                    {
                        conflictFields.AddressLine1 = addresses.Line1;
                        conflictFields.AddressLine2 = addresses.Line2;
                        conflictFields.AddressLine3 = addresses.Line3;
                        conflictFields.AddressCountry = addresses.Country;
                        conflictFields.AddressCounty = addresses.County;
                        conflictFields.AddressDepLocality = addresses.DependantLocality;
                        conflictFields.AddressDept = addresses.Department;
                        conflictFields.AddressDXNumber = addresses.DXNumber;
                        conflictFields.AddressDXTown = addresses.DXTown;
                        conflictFields.AddressHouseName = addresses.HouseName;
                        conflictFields.AddressOrgName = addresses.OrganisationName;
                        conflictFields.AddressPoBox = addresses.PostBox;
                        conflictFields.AddressPostCode = addresses.PostCode;
                        conflictFields.AddressStreetNo = addresses.StreetNumber;
                        conflictFields.AddressSubBldg = addresses.SubBuilding;
                        conflictFields.AddressTown = addresses.Town;
                    }

                    if (addressInformation != null)
                    {
                        for (int i = 0; i <= addressInformation.Count - 1; i++)
                        {
                            switch (i)
                            {
                                case 0:
                                    conflictFields.ConflictCheck1 = addressInformation[i].ElementText;
                                    break;
                                case 1:
                                    conflictFields.ConflictCheck2 = addressInformation[i].ElementText;
                                    break;
                                case 2:
                                    conflictFields.ConflictCheck3 = addressInformation[i].ElementText;
                                    break;
                                case 3:
                                    conflictFields.ConflictCheck4 = addressInformation[i].ElementText;
                                    break;
                                case 4:
                                    conflictFields.ConflictCheck5 = addressInformation[i].ElementText;
                                    break;
                                case 5:
                                    conflictFields.ConflictCheck6 = addressInformation[i].ElementText;
                                    break;
                                case 6:
                                    conflictFields.ConflictCheck7 = addressInformation[i].ElementText;
                                    break;
                                case 7:
                                    conflictFields.ConflictCheck8 = addressInformation[i].ElementText;
                                    break;
                                case 8:
                                    conflictFields.ConflictCheck9 = addressInformation[i].ElementText;
                                    break;
                                case 9:
                                    conflictFields.ConflictCheck10 = addressInformation[i].ElementText;
                                    break;
                            }
                        }
                    }

                    //dsConflictCheckStandard = conflictCheck.DoConflictCheck(conflictFields, ApplicationSettings.Instance.DbUid);
                    IRIS.Law.PmsCommonData.DsConflictCheckStandard dsConflictCheckStandard1 = null;
                    IRIS.Law.PmsCommonData.DsConflictCheckAddress dsConflictCheckAddress1 = null;
                    IRIS.Law.PmsCommonData.DsConflictCheckAdditionalAddress dsConflictCheckAdditionalAddress1 = null;
                    IRIS.Law.PmsCommonData.DsConflictCheckExtendedInfo dsConflictCheckExtendedInfo1 = null;
                    var sbSummary = conflictCheck.DoConflictCheck(conflictFields, out dsConflictCheckStandard1, out dsConflictCheckAddress1, out dsConflictCheckAdditionalAddress1, out dsConflictCheckExtendedInfo1, DataConstants.DummyGuid, checkOnAllRoles);

                    if (dsConflictCheckStandard1.uvw_ConflictCheckStandard.Rows.Count > 0 || dsConflictCheckAddress1.uvw_ConflictCheckAddress.Rows.Count > 0 || dsConflictCheckAdditionalAddress1.uvw_ConflictCheckAdditionalAddress.Rows.Count > 0 || dsConflictCheckExtendedInfo1.uvw_ConflictCheckExtendedInfo.Rows.Count > 0)
                    {
                        returnValue.IsConflict = true;
                    }
                    else
                    {
                        returnValue.IsConflict = false;
                    }

                    returnValue.Summary = new StringBuilder(sbSummary);

                    collectionRequest.ForceRefresh = true;

                    //returnValue.IsConflict = conflictCheck.IsConflict;

                    dataListCreator.ReadDataSet += delegate(object Sender, ReadDataSetEventArgs e)
                    {
                        // Perform Sorting on SelectType
                        DataView dvConflictCheck = new DataView(dsConflictCheckStandard1.Tables[0]);
                        dvConflictCheck.Sort = "SelectType asc";

                        DataSet dsSorted = new DataSet();
                        dsSorted.Tables.Add(dvConflictCheck.ToTable());
                        e.DataSet = dsSorted;
                        //e.DataSet = dsConflictCheckStandard1;
                    };

                    returnValue.ConflictCheckStandard = dataListCreator.Create(logonId,
                        // Give the query a name so it can be cached
                        "ConflictCheckStandard",
                        // Tell it the query criteria used so if the cache is accessed
                        // again it knows if it is the same query
                        "",
                        collectionRequest,
                        // Import mappings to map the dataset row fields to the data
                        // list entity properties
                        new ImportMapping[] {
                            new ImportMapping("ClientRef", "cliRef"),
                            new ImportMapping("SelectType", "SelectType"),
                            new ImportMapping("PersonTitle", "PersonTitle"),
                            new ImportMapping("PersonName", "PersonName"),
                            new ImportMapping("PersonSurName", "PersonSurName"),
                            new ImportMapping("AddressStreetNo", "AddressStreetNo"),
                            new ImportMapping("AddressHouseName", "AddressHouseName"),
                            new ImportMapping("AddressLine1", "AddressLine1"),
                            new ImportMapping("OrgName", "OrgName"),
                            new ImportMapping("IsMember", "IsMember")
                            }
                        );
                }
                finally
                {
                    // Remove the logged on user's ApplicationSettings from the
                    // list of concurrent sessions
                    Host.UnloadLoggedOnUser();
                }
            }
            catch (Exception Ex)
            {
                returnValue.Success = false;
                returnValue.Message = "Could not load conflict check fields for the current user." + Ex.Message;
            }

            return returnValue;
        }