///<summary>
 /// Opens the connection/transaction for the given connectionString, and closes them when complete
 ///<summary>
 public static FR_L5RE_GREFTWSP_0846 Invoke(string ConnectionString, P_L5RE_GREFTWSP_0846 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
 {
     return(Invoke(null, null, ConnectionString, Parameter, securityTicket));
 }
        ///<summary>
        /// Method Invocation of wrapper classes
        ///<summary>
        protected static FR_L5RE_GREFTWSP_0846 Invoke(DbConnection Connection, DbTransaction Transaction, string ConnectionString, P_L5RE_GREFTWSP_0846 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            bool cleanupConnection  = Connection == null;
            bool cleanupTransaction = Transaction == null;

            FR_L5RE_GREFTWSP_0846 functionReturn = new FR_L5RE_GREFTWSP_0846();

            try
            {
                if (cleanupConnection == true)
                {
                    Connection = CSV2Core_MySQL.Support.DBSQLSupport.CreateConnection(ConnectionString);
                    Connection.Open();
                }
                if (cleanupTransaction == true)
                {
                    Transaction = Connection.BeginTransaction();
                }

                functionReturn = Execute(Connection, Transaction, Parameter, securityTicket);

                #region Cleanup Connection/Transaction
                //Commit the transaction
                if (cleanupTransaction == true)
                {
                    Transaction.Commit();
                }
                //Close the connection
                if (cleanupConnection == true)
                {
                    Connection.Close();
                }
                #endregion
            }
            catch (Exception ex)
            {
                try
                {
                    if (cleanupTransaction == true && Transaction != null)
                    {
                        Transaction.Rollback();
                    }
                }
                catch { }

                try
                {
                    if (cleanupConnection == true && Connection != null)
                    {
                        Connection.Close();
                    }
                }
                catch { }

                throw new Exception("Exception occured in method cls_Get_Realestates_For_Tenant_With_SearchParams", ex);
            }
            return(functionReturn);
        }
        protected static FR_L5RE_GREFTWSP_0846 Execute(DbConnection Connection, DbTransaction Transaction, P_L5RE_GREFTWSP_0846 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            #region UserCode
            var returnValue = new FR_L5RE_GREFTWSP_0846();


            L5RE_GREFT_1534[] allRealEstates = cls_Get_Realestates_For_Tenant.Invoke(Connection, Transaction, securityTicket).Result;


            if (Parameter.FromDate.Ticks != 0)
            {
                allRealEstates = allRealEstates.Where(i => i.Creation_Timestamp.Date >= Parameter.FromDate).ToArray();
            }
            if (Parameter.ToDate.Ticks != 0)
            {
                allRealEstates = allRealEstates.Where(i => i.Creation_Timestamp.Date <= Parameter.ToDate).ToArray();
            }
            if (Parameter.FirstName != "")
            {
                allRealEstates = allRealEstates.Where(i => i.FirstName.ToLower().Contains(Parameter.FirstName.ToLower())).ToArray();
            }
            if (Parameter.LastName != "")
            {
                allRealEstates = allRealEstates.Where(i => i.LastName.ToLower().Contains(Parameter.LastName.ToLower())).ToArray();
            }
            if (Parameter.Title != "")
            {
                allRealEstates = allRealEstates.Where(i => i.RealestateProperty_Title.ToLower().Contains(Parameter.Title.ToLower())).ToArray();
            }

            if (Parameter.IsArchived && !Parameter.IsLocked)
            {
                allRealEstates = allRealEstates.Where(i => i.IsArchived == Parameter.IsArchived).ToArray();
            }
            else if (!Parameter.IsArchived && Parameter.IsLocked)
            {
                allRealEstates = allRealEstates.Where(i => i.IsLocked == Parameter.IsLocked).ToArray();
            }
            else if (Parameter.IsArchived && Parameter.IsLocked)
            {
                allRealEstates = allRealEstates.Where(i => i.IsArchived == Parameter.IsArchived || i.IsLocked == Parameter.IsLocked).ToArray();
            }


            returnValue.Result = new L5RE_GREFTWSP_0846();
            returnValue.Result.RealestateProperties = allRealEstates;

            //Put your code here
            return(returnValue);

            #endregion UserCode
        }
 ///<summary>
 /// Invokes the method for the given Connection, and Transaction, leaving them open/not commited if no exceptions occured
 ///<summary>
 public static FR_L5RE_GREFTWSP_0846 Invoke(DbConnection Connection, DbTransaction Transaction, P_L5RE_GREFTWSP_0846 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
 {
     return(Invoke(Connection, Transaction, null, Parameter, securityTicket));
 }