/// <summary>
        /// Call this to say the download is finished
        /// </summary>
        /// <param name="logonId"></param>
        /// <param name="TransferId">Transfer id obtained when starting the download</param>
        /// <returns></returns>
        public ReturnValue DocumentDownloadComplete(Guid logonId, Guid TransferId)
        {
            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
                {
                    FileTransfer.DownloadComplete(logonId, TransferId);
                }
                finally
                {
                    // Remove the logged on user's ApplicationSettings from the
                    // list of concurrent sessions
                    Host.UnloadLoggedOnUser();
                }
            }
            catch (Exception ex)
            {
                ReturnValue.Success = false;
                ReturnValue.Message = ex.Message;
            }

            return ReturnValue;
        }
 public ReturnValue DeleteBooking(HostSecurityToken oHostSecurityToken, DeleteData deleteData)
 {
     ReturnValue returnValue = null;
     if (Functions.ValidateIWSToken(oHostSecurityToken))
     {
         oDiaryService = new DiaryService();
         returnValue = oDiaryService.DeleteBooking(Functions.GetLogonIdFromToken(oHostSecurityToken), deleteData);
     }
     else
     {
         returnValue = new ReturnValue();
         returnValue.Success = false;
         returnValue.Message = "Invalid Token";
     }
     return returnValue;
 }
 /// <summary>
 /// Adds the association for matter.
 /// </summary>
 /// <param name="oHostSecurityToken">HostSecurityToken obtained when security provider of IWS is called</param>
 /// <param name="association">The association.</param>
 /// <returns></returns>
 public ReturnValue AddAssociationForMatter(HostSecurityToken oHostSecurityToken, AssociationForMatter association)
 {
     ReturnValue returnValue = null;
     if (Functions.ValidateIWSToken(oHostSecurityToken))
     {
         oContactService = new ContactService();
         returnValue = oContactService.AddAssociationForMatter(Functions.GetLogonIdFromToken(oHostSecurityToken),
             association);
     }
     else
     {
         returnValue = new ReturnValue();
         returnValue.Success = false;
         returnValue.Message = "Invalid Token";
     }
     return returnValue;
 }
        /// <summary>
        /// Log on to the services
        /// </summary>
        /// <param name="userName"></param>
        /// <param name="password"></param>
        /// <returns></returns>
        public ReturnValue LogonVerify(HostSecurityToken oHostSecurityToken)
        {
            ReturnValue returnValue = new ReturnValue();
            try
            {
                UserState userState = null;
                userState = Host.GetUserState(Functions.GetLogonIdFromToken(oHostSecurityToken));
                returnValue.Success = true;
            }
            catch (Exception ex)
            {
                returnValue.Success = false;
                returnValue.Message = ex.Message;
            }

            return returnValue;
        }
 /// <summary>
 /// Update an existing client's address or add a new one
 /// </summary>
 /// <param name="oHostSecurityToken">HostSecurityToken obtained when security provider of IWS is called</param>
 /// <param name="memberId">Member id of the client</param>
 /// <param name="organisationId">Orgainisation id of the client</param>
 /// <param name="address">Address to update or new address to add.
 /// If the Address.Id = 0 then a new address is being added.</param>
 /// <returns></returns>
 public ReturnValue UpdateClientAddress(HostSecurityToken oHostSecurityToken, Guid memberId,
     Guid organisationId, Address address)
 {
     ReturnValue returnValue = null;
     if (Functions.ValidateIWSToken(oHostSecurityToken))
     {
         oClientService = new ClientService();
         returnValue = oClientService.UpdateClientAddress(Functions.GetLogonIdFromToken(oHostSecurityToken), memberId, organisationId, address);
     }
     else
     {
         returnValue = new ReturnValue();
         returnValue.Success = false;
         returnValue.Message = "Invalid Token";
     }
     return returnValue;
 }
        /// <summary>
        /// Update an existing matter
        /// </summary>
        /// <param name="logonId">Logon id obtained when logging on to the logon service</param>
        /// <param name="matter">Matter details</param>
        /// <returns></returns>
        public ReturnValue UpdateMatter(Guid logonId, Matter matter)
        {
            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:
                            throw new Exception("Access denied");
                        default:
                            throw new Exception("Access denied");
                    }

                    SrvMatter srvMatter = new SrvMatter();
                    srvMatter.Load(matter.Id);

                    // Save Matter Details
                    srvMatter.ProjectId = matter.Id;
                    srvMatter.MatterDescription = matter.Description;
                    srvMatter.MatterKeyDescription = matter.KeyDescription;
                    srvMatter.FeeEarnerMemberId = matter.FeeEarnerMemberId;
                    srvMatter.MatterPartnerMemberId = matter.PartnerMemberId;
                    srvMatter.CurrentWorkTypeId = matter.WorkTypeId;
                    srvMatter.ClientBankId = matter.ClientBankId;
                    srvMatter.OfficeBankId = matter.OfficeBankId;
                    srvMatter.MatterDepositBankId = matter.DepositBankId;
                    srvMatter.BranchId = matter.BranchReference;
                    srvMatter.DepartmentId = matter.DepartmentId;
                    srvMatter.ChargeDescriptionId = matter.ChargeDescriptionId;
                    srvMatter.CourtId = matter.CourtId;
                    srvMatter.MatterOpenDate = matter.OpenDate;
                    srvMatter.MatterNextReviewDate = matter.NextReviewDate;
                    srvMatter.MatterCostReviewDate = matter.CostReviewDate;
                    srvMatter.MatterClosedDate = matter.ClosedDate;
                    srvMatter.MatterDestructDate = matter.DestructDate;
                    srvMatter.MatterFileNo = matter.FileNo;
                    srvMatter.MatterCompleted = matter.CompletedDate;

                    // Save Matter Additional Info
                    srvMatter.MatterQuote = matter.Quote;
                    srvMatter.MatterDisbsLimit = matter.DisbsLimit;
                    srvMatter.MatterTimeLimit = matter.TimeLimit;
                    srvMatter.MatterWIPLimit = matter.WIPLimit;
                    srvMatter.MatterOverallLimit = matter.OverallLimit;
                    srvMatter.MatterStatus = matter.Status;
                    srvMatter.MatterIndicators = matter.Indicators;
                    srvMatter.MatterBankReference = matter.BankReference;
                    srvMatter.MatCashCollID = matter.CashCollectionId;
                    srvMatter.MatTotalLockup = matter.TotalLockup;
                    srvMatter.OurReference = matter.OurReference;
                    srvMatter.PreviousReference = matter.PreviousReference;
                    srvMatter.SourceID = matter.BusinessSourceId;
                    // TODO: Save Campaign Id
                    // = campaignId = matter.SourceCampaignId;
                    srvMatter.UserId = matter.PersonDealingId;
                    srvMatter.MatterSalutationEnvelope = matter.SalutationEnvelope;
                    srvMatter.MatterSalutationLetter = matter.SalutationLetter;
                    srvMatter.MatterLetterHead = matter.LetterHead;

                    //Save Matter Public Funding
                    srvMatter.MatterLegalAided = matter.IsPublicFunding;
                    srvMatter.MatterFranchised = matter.Franchised;
                    srvMatter.MatterLondonRate = matter.isLondonRate;
                    srvMatter.UFNDate = matter.UFNDate;
                    srvMatter.UFNNumber = matter.UFN;
                    srvMatter.MatterPFCertificateNo = matter.PFCertificateNo;
                    srvMatter.MatterPFCertificateLimits = matter.PFCertificateNoLimits;
                    srvMatter.MatterTypeId = matter.MatterTypeId;

                    srvMatter.ClientId = matter.ClientId;

                    string errorMessage;

                    returnValue.Success = srvMatter.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;
        }
        public ReturnValue DocumentUploadComplete(Guid logonId, Guid TransferId)
        {
            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
                {
                    FileUploadInfo FileUploadInfo = FileTransfer.UploadComplete(logonId, TransferId);

                    DocumentStorageData DocumentStorageData = Host.GetDocumentStorageData(logonId);

                    // DocumentStorageData holds all the information needed to know how to store the document

                    // TODO this is just test code.  You should replace this with code to store the file
                    // in the ILB document management system.
                    // FileUploadInfo.TempFileName holds the full path to the actual file that has been uploaded
                    // FileUploadInfo.FileName holds the original file name (excluding path) of the file that has been uploaded
                    // The file will need moving to the correct location in the document management system.
                    File.Move(FileUploadInfo.TempFileName, @"c:\Work\Uploaded\" + FileUploadInfo.FileName);

                    FileTransfer.UploadReset(logonId, TransferId);
                }
                finally
                {
                    // Remove the logged on user's ApplicationSettings from the
                    // list of concurrent sessions
                    Host.UnloadLoggedOnUser();
                }
            }
            catch (Exception ex)
            {
                ReturnValue.Success = false;
                ReturnValue.Message = ex.Message;
            }

            return ReturnValue;
        }
 /// <summary>
 /// Update an existing client
 /// </summary>
 /// <param name="oHostSecurityToken">HostSecurityToken obtained when security provider of IWS is called</param>
 /// <param name="client">Client details</param>
 /// <param name="person"></param>
 /// <param name="organisation"></param>
 /// <returns></returns>
 public IRIS.Law.WebServiceInterfaces.ReturnValue UpdateClient(HostSecurityToken oHostSecurityToken, Client client,
                                                 Person person, Organisation organisation)
 {
     ReturnValue returnValue = null;
     if (Functions.ValidateIWSToken(oHostSecurityToken))
     {
         oClientService = new ClientService();
         returnValue = oClientService.UpdateClient(Functions.GetLogonIdFromToken(oHostSecurityToken), client, person, organisation);
     }
     else
     {
         returnValue = new ReturnValue();
         returnValue.Success = false;
         returnValue.Message = "Invalid Token";
     }
     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(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>
        /// Request Password method.
        /// </summary>
        /// <returns></returns>
        public ReturnValue RequestPassword(string userName)
        {
            ReturnValue returnValue = new ReturnValue();

            try
            {
                try
                {
                    ApplicationSettings.NewSession();

                    SrvPmsPassGen newPassword = new SrvPmsPassGen();
                    string Password;
                    string error;
                    string warning;
                    SrvPassword srvPassword = new SrvPassword();

                    UserInformation.Instance.DbLogon= userName;

                    srvPassword.Load(userName);
                    //srvPassword.OriginalPassword = srvPassword.UserPassword;

                    if (srvPassword.UserName==null)
                        throw new Exception("Not a valid user");

                    //Make sure the password we have generated passes validation
                    do
                    {
                        Password = newPassword.GenStrongPass(10);
                        srvPassword.NewPassword = Password;
                    } while (srvPassword.ValidateNewPassword(out error, out warning) == false);

                    srvPassword.RepeatPassword = Password;
                    srvPassword.RequireChange = false;
                    srvPassword.ResetUserLoggedIn = true;

                    try
                    {
                        srvPassword.Save();
                    }
                    catch(Exception ex) {
                        returnValue.Success = false;
                        returnValue.Message = ex.Message;
                    }

                    if (error == string.Empty)
                    {
                        returnValue.Success = true;
                    }
                    else
                    {
                        returnValue.Success = false;
                        returnValue.Message = error;
                    }

                    //Send E-mail;

                    //create the mail message
                    MailMessage mail = new MailMessage();

                    //set the addresses
                    mail.From = new MailAddress(userName);
                    mail.To.Add(userName);

                    //set the content
                    mail.Subject = "Fee Earner Desktop - New Password";

                    string emailBody = "<p style='font-family:arial;font-size:8pt'><b>Your new password for the Fee Earner Desktop is - </b> " + Password + " </p><br/>";
                    emailBody += "<br/><br/><b>Please do not reply to this e-mail.</b>";
                    emailBody += "</table>";

                    mail.Body = emailBody;
                    mail.IsBodyHtml = true;

                    //send the message
                    SmtpClient smtp = new SmtpClient();
                    smtp.Host = ConfigurationManager.AppSettings["SMTPHost"].ToString();
                    smtp.Port = int.Parse(ConfigurationManager.AppSettings["SMTPPort"].ToString());

                    if (ConfigurationManager.AppSettings["SMTPUserName"].ToString() != string.Empty && ConfigurationManager.AppSettings["SMTPPassword"].ToString() != string.Empty)
                    {
                        System.Net.NetworkCredential credentials = new System.Net.NetworkCredential(ConfigurationManager.AppSettings["SMTPUserName"].ToString(), ConfigurationManager.AppSettings["SMTPPassword"].ToString());
                        smtp.Credentials = credentials;
                        smtp.UseDefaultCredentials = false;
                    }
                    else
                    {
                        smtp.UseDefaultCredentials = true;
                    }

                    if (ConfigurationManager.AppSettings["IISVersion"].ToString() == "7")
                        smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
                    else
                        smtp.DeliveryMethod = SmtpDeliveryMethod.PickupDirectoryFromIis;

                    smtp.Send(mail);
                }
                finally
                {
                    ApplicationSettings.RemoveSession();
                }

            }
            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>
        /// Authorise unauthorised cheque requests for client and office.
        /// </summary>
        /// <param name="logonId">Logon id obtained when logging on to the logon service</param>
        /// <param name="selectedChequeRequestsIds">Selected cheque request ids for authorisation</param>
        /// <param name="isClientChequeRequest"></param>
        /// <returns>Authorise selected unauthorised cheque request ids.</returns>
        public ReturnValue AuthoriseChequeRequests(Guid logonId, List<int> selectedChequeRequestsIds, bool isClientChequeRequest)
        {
            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:
                            throw new Exception("Access denied");
                        default:
                            throw new Exception("Access denied");
                    }
                    decimal clientChequeRequestHigherAmount = decimal.Zero;
                    decimal officeChequeRequestHigherAmount = decimal.Zero;

                    if (selectedChequeRequestsIds.Count > 0)
                    {
                        // Verifies whether cheque request is allowed for  authorisation
                        // else it will set error message.
                        if (this.CheckUserAllowedToAuthoriseChqReqHigherAmount(selectedChequeRequestsIds, isClientChequeRequest, out clientChequeRequestHigherAmount, out officeChequeRequestHigherAmount))
                        {
                            for (int index = 0; index < selectedChequeRequestsIds.Count; index++)
                            {
                                int chequeRequestId = Convert.ToInt32(selectedChequeRequestsIds[index].ToString().Trim());

                                if (isClientChequeRequest)
                                {
                                    //if (!UserSecuritySettings.GetUserSecuitySettings(151)
                                    // || !UserSecuritySettings.GetUserSecuitySettings(162))

                                    if (!UserSecuritySettings.GetUserSecuitySettings((int)AccountsSettings.AuthoriseClientChequeRequest)
                                        || !UserSecuritySettings.GetUserSecuitySettings((int)AccountsSettings.AutomaticallyAuthoriseChequeRequests))
                                        throw new Exception("You do not have sufficient permissions to carry out this request");

                                    SrvClientChequeRequestCommon.AddAuthoriseClientChequeRequests(chequeRequestId, UserInformation.Instance.UserMemberId, DateTime.Now);
                                }
                                else
                                {
                                    //if (!UserSecuritySettings.GetUserSecuitySettings(164)
                                    //|| !UserSecuritySettings.GetUserSecuitySettings(162))
                                    if (!UserSecuritySettings.GetUserSecuitySettings((int)AccountsSettings.AuthoriseOfficeChequeRequest)
                                            || !UserSecuritySettings.GetUserSecuitySettings((int)AccountsSettings.AutomaticallyAuthoriseChequeRequests))
                                        throw new Exception("You do not have sufficient permissions to carry out this request");

                                    SrvOfficeChequeRequestCommon.AddAuthoriseOfficeChequeRequests(chequeRequestId, UserInformation.Instance.UserMemberId, DateTime.Now);
                                }
                            }
                        }
                        else
                        {
                            if (isClientChequeRequest)
                            {
                                returnValue.Message = "You are not allowed to Authorise Office Cheque Requests over the value of £" +
                                                        clientChequeRequestHigherAmount.ToString("0.00") + ".";
                            }
                            else
                            {
                                returnValue.Message = "You are not allowed to Authorise Office Cheque Requests over the value of £" +
                                                        officeChequeRequestHigherAmount.ToString("0.00") + ".";
                            }
                        }
                    }
                }
                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>
        /// Saves the service contact.
        /// </summary>
        /// <param name="logonId">Logon id obtained when logging on to the logon service.</param>
        /// <param name="contactAddress">The contact address.</param>
        /// <param name="additionalElement">The additional element.</param>
        /// <param name="serviceContact">The service contact.</param>
        /// <param name="conflictNoteSummary">The conflict note summary.</param>
        /// <param name="conflictNoteContent">Content of the conflict note.</param>
        /// <returns></returns>
        public ReturnValue SaveServiceContact(Guid logonId, Address contactAddress,
                                       AdditionalAddressElement[] additionalElement,
                                       ServiceContact serviceContact,
                                       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");
                    }

                    SrvServiceContact serviceContactSrv = new SrvServiceContact();
                    SrvAddress srvAddress = new SrvAddress();

                    this.SetAddressValue(srvAddress, contactAddress);

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

                    serviceContactSrv.ServiceId = serviceContact.ServiceId;
                    serviceContactSrv.Person.ForeName = serviceContact.ForeName;
                    serviceContactSrv.Person.Surname = serviceContact.SurName;
                    serviceContactSrv.Person.Title = serviceContact.Title;
                    serviceContactSrv.Position = serviceContact.Position;
                    serviceContactSrv.Person.Sex = serviceContact.Sex;

                    //These two notes fields are mandatory and have defined
                    //default values
                    serviceContactSrv.ConflictNoteSummary = conflictNoteSummary;
                    serviceContactSrv.ConflictNoteContent = conflictNoteContent;

                    string errorMessage;

                    returnValue.Success = serviceContactSrv.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>
 /// Validates the time type.
 /// </summary>
 /// <param name="oHostSecurityToken">User token</param>
 /// <param name="criteria">The criteria.</param>
 /// <returns></returns>
 public ReturnValue ValidateTimeTypeForPosting(HostSecurityToken oHostSecurityToken, TimeTypeCriteria criteria)
 {
     ReturnValue returnValue = null;
     if (Functions.ValidateIWSToken(oHostSecurityToken))
     {
         oTimeService = new TimeService();
         returnValue = oTimeService.ValidateTimeTypeForPosting(Functions.GetLogonIdFromToken(oHostSecurityToken), criteria);
     }
     else
     {
         returnValue = new ReturnValue();
         returnValue.Success = false;
         returnValue.Message = "Invalid Token";
     }
     return returnValue;
 }
        public ReturnValue DeleteBooking(Guid logonId, DeleteData deleteData)
        {
            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:
                            // Ensure we have permission
                            if (!UserSecuritySettings.GetUserSecuitySettings(103))
                                throw new Exception("You do not have sufficient permissions to carry out this request");
                            break;
                        case DataConstants.UserType.Client:
                        case DataConstants.UserType.ThirdParty:
                            throw new Exception("Access denied");
                        default:
                            throw new Exception("Access denied");
                    }

                    BookingDeleteData bookingDeleteData = new BookingDeleteData();
                    bookingDeleteData.OccurrenceID = deleteData.OccurenceId;
                    bookingDeleteData.MemberID = Convert.ToString(UserInformation.Instance.UserMemberId);
                    bookingDeleteData.IsBookingATask = deleteData.IsBookingATask;
                    bookingDeleteData.BlockBookingDeleteDataSet = new BookingDeleteDts();
                    bookingDeleteData.GroupBookingDeleteDataSet = new BookingDeleteDts();

                    try
                    {
                        string occurrenceMember;
                        DiaryMemberSearchItem diaryMembers = this.GetDiaryMemberDetails(deleteData.MemberId);

                        if (diaryMembers.IsGroup)
                        {
                            DiaryBookingsDts dsOccurrence = SrvOccurrenceLookup.GetOccurrenceById(deleteData.OccurenceId);
                            if (dsOccurrence.Occurrence.Rows.Count == 1)
                            {
                                occurrenceMember = dsOccurrence.Occurrence[0].MemberID.ToString();
                            }
                            else
                            {
                                occurrenceMember = Guid.Empty.ToString();
                            }
                        }
                        else
                        {
                            occurrenceMember = deleteData.MemberId;
                        }

                        // Firstly get the block bookings
                        bookingDeleteData.BlockBookingDeleteDataSet = SrvBookingEntryLookup.GetDiaryBookingsForDelete(occurrenceMember, deleteData.OccurenceId, 1);

                        if (bookingDeleteData.BlockBookingDeleteDataSet != null)
                        {
                            // Now get group booking
                            bookingDeleteData.GroupBookingDeleteDataSet = SrvBookingEntryLookup.GetDiaryBookingsForDelete(occurrenceMember, deleteData.OccurenceId, 2);
                        }

                        if (bookingDeleteData.GroupBookingDeleteDataSet != null)
                        {
                            BookingDeleteDts tempDts = SrvBookingEntryLookup.GetBookingMembersForDelete(deleteData.OccurenceId);
                            foreach (BookingDeleteDts.BookingMembersDeleteRow dr in tempDts.BookingMembersDelete.Rows)
                            {
                                bookingDeleteData.GroupBookingDeleteDataSet.BookingMembersDelete.AddBookingMembersDeleteRow(dr.MemberID, dr.MemberDisplayName);
                            }
                        }

                        bookingDeleteData.IsBlockBooking = (bookingDeleteData.BlockBookingDeleteDataSet.BookingDelete.Rows.Count > 1);
                        bookingDeleteData.IsGroupBooking = (bookingDeleteData.GroupBookingDeleteDataSet.BookingMembersDelete.Rows.Count > 1);

                        if (bookingDeleteData.IsBlockBooking)
                        {
                            for (int i = 0; i < bookingDeleteData.GroupBookingDeleteDataSet.BookingDelete.Rows.Count; i++)
                            {
                                bookingDeleteData.GroupBookingDeleteDataSet.BookingDelete.Rows[i]["DeleteFlag"] = 1;
                            }
                        }
                        else if (bookingDeleteData.IsGroupBooking)
                        {
                            for (int i = 0; i < bookingDeleteData.GroupBookingDeleteDataSet.BookingDelete.Rows.Count; i++)
                            {
                                bookingDeleteData.GroupBookingDeleteDataSet.BookingDelete.Rows[i]["DeleteFlag"] = 1;
                            }
                        }

                        // Delete Occurrences
                        SrvBookingEntry srvBooking = new SrvBookingEntry();
                        string occurrenceIDs = string.Empty;
                        foreach (DataRow dr in bookingDeleteData.GroupBookingDeleteDataSet.BookingDelete.Rows)
                        {
                            if ((bool)dr["DeleteFlag"])
                            {
                                occurrenceIDs += (dr["OccurrenceID"].ToString() + ",");
                            }
                        }

                        if (!string.IsNullOrEmpty(occurrenceIDs))
                        {
                            occurrenceIDs = occurrenceIDs.Substring(0, occurrenceIDs.Length - 1);
                            string[] strOccurerenceIds = occurrenceIDs.Split(',');
                            int[] occurerenceIds = new int[strOccurerenceIds.Length];

                            for (int i = 0; i < strOccurerenceIds.Length; i++)
                            {
                                occurerenceIds[i] = Convert.ToInt32(strOccurerenceIds[i]);
                            }

                            if (!srvBooking.Delete(occurerenceIds, deleteData.CategoryCode, deleteData.ReasonCode, deleteData.CancellationText))
                            {
                                throw new Exception("Some of the supplied occurrences are already cancelled!");
                            }
                        }
                        else
                        {
                            throw new Exception("Please provide valid Occurrence Ids.");
                        }

                    }
                    catch (Exception ex)
                    {
                        throw new Exception(ex.Message);
                    }
                }
                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>
 /// Post todays time sheets for accounting 
 /// </summary>
 /// <param name="oHostSecurityToken">User token</param>
 /// <param name="timeSheet">Fee Earner Time Sheet</param>
 /// <returns></returns>
 public ReturnValue PostTime(HostSecurityToken oHostSecurityToken, TimeSheet timeSheet)
 {
     ReturnValue returnValue = null;
     if (Functions.ValidateIWSToken(oHostSecurityToken))
     {
         oTimeService = new TimeService();
         returnValue = oTimeService.PostTime(Functions.GetLogonIdFromToken(oHostSecurityToken), timeSheet);
     }
     else
     {
         returnValue = new ReturnValue();
         returnValue.Success = false;
         returnValue.Message = "Invalid Token";
     }
     return returnValue;
 }
 /// <summary>
 /// Authorise unauthorised cheque requests for client and office.
 /// </summary>
 /// <param name="oHostSecurityToken">HostSecurityToken obtained when security provider of IWS is called</param>
 /// <param name="selectedChequeRequestsIds">Selected cheque request ids for authorisation</param>
 /// <param name="isClientChequeRequest"></param>
 /// <returns>Authorise selected unauthorised cheque request ids.</returns>
 public ReturnValue AuthoriseChequeRequests(HostSecurityToken oHostSecurityToken, List<int> selectedChequeRequestsIds, bool isClientChequeRequest)
 {
     ReturnValue returnValue = null;
     if (Functions.ValidateIWSToken(oHostSecurityToken))
     {
         oAccountService = new AccountsService();
         returnValue = oAccountService.AuthoriseChequeRequests(Functions.GetLogonIdFromToken(oHostSecurityToken), selectedChequeRequestsIds, isClientChequeRequest);
     }
     else
     {
         returnValue = new ReturnValue();
         returnValue.Success = false;
         returnValue.Message = "Invalid Token";
     }
     return returnValue;
 }
        /// <summary>
        /// Change Password method.
        /// </summary>
        /// <returns></returns>
        public ReturnValue ChangePassword(Guid logonId, string userName, string password, string newPassword)
        {
            ReturnValue returnValue = new ReturnValue();

            try
            {
                Host.LoadLoggedOnUser(logonId);

                try
                {
                    switch (UserInformation.Instance.UserType)
                    {
                        case DataConstants.UserType.Staff:
                                throw new Exception("Access denied");
                        case DataConstants.UserType.Client:
                        case DataConstants.UserType.ThirdParty:
                            // Can do everything
                            break;
                        default:
                            throw new Exception("Access denied");
                    }

                    SrvPassword srvPassword = new SrvPassword();
                    srvPassword.Load(userName);
                    srvPassword.OriginalPassword = password;
                    srvPassword.NewPassword = newPassword;
                    srvPassword.RepeatPassword = newPassword;
                    srvPassword.RequireChange = false;
                    string error;

                    if (srvPassword.ValidateAll(out error))
                    {
                        srvPassword.Save(out error);
                    }

                    if (error == string.Empty)
                    {
                        returnValue.Success = true;
                    }
                    else
                    {
                        returnValue.Success = false;
                        returnValue.Message = error;
                    }

                }
                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;
        }
        public ReturnValue DocumentUploadChunk(Guid logonId, Guid TransferId, 
            long FilePosition, int ChunkSize, byte[] Bytes)
        {
            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
                {
                    FileTransfer.UploadChunk(logonId, TransferId, FilePosition, ChunkSize, Bytes);
                }
                finally
                {
                    // Remove the logged on user's ApplicationSettings from the
                    // list of concurrent sessions
                    Host.UnloadLoggedOnUser();
                }
            }
            catch (Exception ex)
            {
                ReturnValue.Success = false;
                ReturnValue.Message = ex.Message;
            }

            return ReturnValue;
        }
        /// <summary>
        /// Adds the association for matter.
        /// </summary>
        /// <param name="logonId">Logon id obtained when logging on to the logon service.</param>
        /// <param name="association">The association.</param>
        /// <returns></returns>
        public ReturnValue AddAssociationForMatter(Guid logonId, AssociationForMatter association)
        {
            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);
                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");
                }

                SrvAssociationForMatter _srvAssociationForMatter = new SrvAssociationForMatter();
                _srvAssociationForMatter.ApplicationId = association.ApplicationId;
                _srvAssociationForMatter.ProjectId = association.ProjectId;
                _srvAssociationForMatter.RoleId = association.RoleId;
                _srvAssociationForMatter.OrganisationId = association.OrganisationId;
                _srvAssociationForMatter.MemberId = association.MemberId;
                _srvAssociationForMatter.Description = association.Description;
                _srvAssociationForMatter.DateFrom = association.DateFrom;
                _srvAssociationForMatter.DateTo = association.DateTo;
                _srvAssociationForMatter.Reference = association.Reference;
                _srvAssociationForMatter.LetterHead = association.LetterHead;
                _srvAssociationForMatter.Comment = association.Comment;
                _srvAssociationForMatter.LinkedProjectId = association.LinkedProjectId;

                //Code from MsRoleExtendedInfo.cs
                // fill out some default values for personal reps
                if (association.RoleId == 61)
                {
                    //Static method call to the service layer..
                    DsMatterAssociations dmatAssoc = SrvAssociationLookup.GetMatterAssociations(association.ProjectId, "Personal Representative");

                    SrvRoleExtendedInfo roleExtendedInfo = new SrvRoleExtendedInfo();
                    roleExtendedInfo.RoleExtendedInfoTypeId = 128;
                    roleExtendedInfo.RoleExtendedInfoNumber = decimal.Zero;
                    roleExtendedInfo.RoleExtendedInfoDate = DataConstants.BlankDate;
                    roleExtendedInfo.RoleExtendedInfoComment = string.Empty;
                    if (dmatAssoc == null || dmatAssoc.uvw_ProjectAssociations.Count == 0)
                    {
                        roleExtendedInfo.RoleExtendedInfoText = "1";
                    }
                    else
                    {
                        roleExtendedInfo.RoleExtendedInfoText = "0";
                    }
                    _srvAssociationForMatter.RoleExtendedInfoDetails.Add(roleExtendedInfo);
                }

                if (association.RoleExtendedInfoDetails != null)
                {
                    //Get role info
                    foreach (RoleExtendedInfo info in association.RoleExtendedInfoDetails)
                    {
                        SrvRoleExtendedInfo roleExtendedInfo = new SrvRoleExtendedInfo();
                        roleExtendedInfo.RoleExtendedInfoTypeId = info.TypeId;
                        roleExtendedInfo.RoleExtendedInfoText = info.Text;
                        roleExtendedInfo.RoleExtendedInfoNumber = info.Number;
                        roleExtendedInfo.RoleExtendedInfoDate = info.Date;
                        roleExtendedInfo.RoleExtendedInfoComment = info.Comment;
                        _srvAssociationForMatter.RoleExtendedInfoDetails.Add(roleExtendedInfo);
                    }
                }

                string errorMessage;

                returnValue.Success = _srvAssociationForMatter.Save(out errorMessage);
                returnValue.Message = errorMessage;
            }
            catch (System.Data.SqlClient.SqlException)
            {
                returnValue.Success = false;
                returnValue.Message = Functions.SQLErrorMessage;
            }
            catch (Exception Ex)
            {
                returnValue.Success = false;
                returnValue.Message = Ex.Message;
            }
            finally
            {
                // Remove the logged on user's ApplicationSettings from the
                // list of concurrent sessions
                Host.UnloadLoggedOnUser();
            }

            return returnValue;
        }
        /// <summary>
        /// Saves the additional address element.
        /// </summary>
        /// <param name="logonId">Logon id obtained when logging on to the logon service.</param>
        /// <param name="additionalElement">The additional element.</param>
        /// <returns></returns>
        public ReturnValue SaveAdditionalAddressElement(Guid logonId,
                                        AdditionalAddressElement additionalElement)
        {
            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.MemberId, additionalElement.OrganisationId))
                                throw new Exception("Access denied");
                            break;
                        default:
                            throw new Exception("Access denied");
                    }

                    SrvAddressAdditionalInfoElement srvAddressAdditionalInfoElement = new SrvAddressAdditionalInfoElement();

                    srvAddressAdditionalInfoElement.Load(additionalElement.MemberId, additionalElement.OrganisationId, additionalElement.TypeId);

                    srvAddressAdditionalInfoElement.AddressId = additionalElement.AddressId;
                    srvAddressAdditionalInfoElement.AddressElementText = additionalElement.ElementText;
                    srvAddressAdditionalInfoElement.AddressElComment = additionalElement.ElementComment;

                    string errorMessage;

                    returnValue.Success = srvAddressAdditionalInfoElement.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>
 /// Update an existing client person
 /// </summary>
 /// <param name="oHostSecurityToken">HostSecurityToken obtained when security provider of IWS is called</param>
 /// <param name="person">Person details</param>
 /// <returns></returns>
 public ReturnValue UpdateClientPerson(HostSecurityToken oHostSecurityToken, Person person)
 {
     ReturnValue returnValue = null;
     if (Functions.ValidateIWSToken(oHostSecurityToken))
     {
         oClientService = new ClientService();
         returnValue = oClientService.UpdateClientPerson(Functions.GetLogonIdFromToken(oHostSecurityToken), person);
     }
     else
     {
         returnValue = new ReturnValue();
         returnValue.Success = false;
         returnValue.Message = "Invalid Token";
     }
     return returnValue;
 }
        /// <summary>
        /// Adds a new service.
        /// </summary>
        /// <param name="logonId">Logon id obtained when logging on to the logon service.</param>
        /// <param name="serviceAddress">The service address.</param>
        /// <param name="serviceAdditionalElement">The service additional element.</param>
        /// <param name="serviceInfo">The service info.</param>
        /// <param name="serviceContactInfo">The service contact info.</param>
        /// <param name="serviceContactAddress">The service contact address.</param>
        /// <param name="ServiceContactAdditionalElement">The service contact additional element.</param>
        /// <param name="conflictNoteSummary">The conflict note summary.</param>
        /// <param name="conflictNoteContent">Content of the conflict note.</param>
        /// <returns></returns>
        public ReturnValue SaveService(Guid logonId, Address serviceAddress,
                                       AdditionalAddressElement[] serviceAdditionalElement,
                                       ServiceInfo serviceInfo,
                                       ServiceContact serviceContactInfo,
                                       Address serviceContactAddress,
                                       AdditionalAddressElement[] ServiceContactAdditionalElement,
                                       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(serviceAdditionalElement[0].MemberId, serviceAdditionalElement[0].OrganisationId))
                                throw new Exception("Access denied");
                            break;
                        default:
                            throw new Exception("Access denied");
                    }

                    SrvService service = new SrvService();
                    SrvAddress srvAddress = new SrvAddress();

                    this.SetAddressValue(srvAddress, serviceAddress);

                    // Save Additional Address Info to Address Object
                    if (serviceAdditionalElement != null)
                    {
                        for (int i = 0; i <= 9; i++)
                        {
                            srvAddress.AdditionalInfoElements[i].AddressElementText = serviceAdditionalElement[i].ElementText;
                        }
                    }
                    service.Addresses.Add(srvAddress);
                    service.Name = serviceInfo.ServiceName;
                    service.NetId = SrvServiceCommon.GenerateNumericPassword(6);
                    service.NetPassword = SrvServiceCommon.GenerateStringPassword(10);
                    service.Organisation.IndustryId = serviceInfo.IndustryId;

                    service.Addresses[0].AddressTypeId = Convert.ToInt32(DataConstants.SystemAddressTypes.Main);
                    service.Addresses[0].MemberId = DataConstants.DummyGuid;
                    service.Addresses[0].OrganisationId = DataConstants.DummyGuid;

                    service.ServiceContact[0].Description = serviceContactInfo.Description;
                    service.ServiceContact[0].Position = serviceContactInfo.Position;
                    service.ServiceContact[0].Person.ForeName = serviceContactInfo.ForeName;
                    service.ServiceContact[0].Person.Surname = serviceContactInfo.SurName;
                    service.ServiceContact[0].Person.Title = serviceContactInfo.Title;
                    service.ServiceContact[0].Person.Sex = serviceContactInfo.Sex;
                    service.ServiceContact[0].ConflictNoteContent = conflictNoteContent;
                    service.ServiceContact[0].ConflictNoteSummary = conflictNoteSummary;

                    SrvAddress contactAddress = new SrvAddress();
                    this.SetAddressValue(contactAddress, serviceContactAddress);

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

                    service.ServiceContact[0].Addresses.Add(contactAddress);
                    service.ServiceContact[0].Addresses[0].MemberId = DataConstants.DummyGuid;
                    service.ServiceContact[0].Addresses[0].OrganisationId = DataConstants.DummyGuid;

                    string errorMessage;

                    returnValue.Success = service.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>
        /// Log off from the services.
        /// </summary>
        /// <param name="logonId">Logon id obtained when logging on to the logon service</param>
        /// <returns></returns>
        public ReturnValue Logoff(Guid logonId)
        {
            ReturnValue returnValue = new ReturnValue();

            try
            {
                Host.RemoveLoggedOnUser(logonId);
            }
            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="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>
 /// Saves the additional address element.
 /// </summary>
 /// <param name="oHostSecurityToken">HostSecurityToken obtained when security provider of IWS is called</param>
 /// <param name="additionalElement">The additional element.</param>
 /// <returns></returns>
 public ReturnValue SaveAdditionalAddressElement(HostSecurityToken oHostSecurityToken,
                                 AdditionalAddressElement additionalElement)
 {
     ReturnValue returnValue = null;
     if (Functions.ValidateIWSToken(oHostSecurityToken))
     {
         oContactService = new ContactService();
         returnValue = oContactService.SaveAdditionalAddressElement(Functions.GetLogonIdFromToken(oHostSecurityToken), additionalElement);
     }
     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;
 }
 /// <summary>
 /// Saves the service contact.
 /// </summary>
 /// <param name="oHostSecurityToken">HostSecurityToken obtained when security provider of IWS is called</param>
 /// <param name="contactAddress">The contact address.</param>
 /// <param name="additionalElement">The additional element.</param>
 /// <param name="serviceContact">The service contact.</param>
 /// <param name="conflictNoteSummary">The conflict note summary.</param>
 /// <param name="conflictNoteContent">Content of the conflict note.</param>
 /// <returns></returns>
 public ReturnValue SaveServiceContact(HostSecurityToken oHostSecurityToken, Address contactAddress,
                                AdditionalAddressElement[] additionalElement,
                                ServiceContact serviceContact,
                                string conflictNoteSummary,
                                string conflictNoteContent)
 {
     ReturnValue returnValue = null;
     if (Functions.ValidateIWSToken(oHostSecurityToken))
     {
         oContactService = new ContactService();
         returnValue = oContactService.SaveServiceContact(Functions.GetLogonIdFromToken(oHostSecurityToken), contactAddress,
             additionalElement, serviceContact, conflictNoteSummary, conflictNoteContent);
     }
     else
     {
         returnValue = new ReturnValue();
         returnValue.Success = false;
         returnValue.Message = "Invalid Token";
     }
     return returnValue;
 }
        /// <summary>
        /// Call this to say the download is finished
        /// </summary>
        /// <param name="logonId"></param>
        /// <param name="TransferId">Transfer id obtained when starting the download</param>
        /// <returns></returns>
        public ReturnValue DocumentDownloadComplete(Guid logonId, Guid TransferId)
        {
            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:
                        case DataConstants.UserType.Client:
                        case DataConstants.UserType.ThirdParty:
                            // Can do everything
                            break;
                        default:
                            throw new Exception("Access denied");
                    }

                    FileTransfer.DownloadComplete(logonId, TransferId);
                }
                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>
 /// Constructs the UCN.
 /// </summary>
 /// <param name="oHostSecurityToken">HostSecurityToken obtained when security provider of IWS is called</param>
 /// <param name="dateOfBirth">The date of birth.</param>
 /// <param name="forename">The forename.</param>
 /// <param name="surname">The surname.</param>
 /// <returns></returns>
 public ReturnValue ConstructUCN(HostSecurityToken oHostSecurityToken, DateTime dateOfBirth, string forename,
                                 string surname)
 {
     ReturnValue returnValue = null;
     if (Functions.ValidateIWSToken(oHostSecurityToken))
     {
         oClientService = new ClientService();
         returnValue = oClientService.ConstructUCN(Functions.GetLogonIdFromToken(oHostSecurityToken), dateOfBirth, forename, surname);
     }
     else
     {
         returnValue = new ReturnValue();
         returnValue.Success = false;
         returnValue.Message = "Invalid Token";
     }
     return returnValue;
 }