/// <summary>
        /// Connects to database and adds modules details.
        /// </summary>
        /// <param name="objList">Object of ModuleInfo.</param>
        /// <param name="isAdmin">Set true if the module is admin.</param>
        /// <param name="PackageID">Package ID.</param>
        /// <param name="IsActive">Set true if the module is active.</param>
        /// <param name="AddedOn">Module added date.</param>
        /// <param name="PortalID">Portal ID.</param>
        /// <param name="AddedBy">Module added user's name.</param>
        /// <returns>Returns array of int containing 1: ModuleID and 2: ModuleDefID.</returns>
        public int[] AddModules(ModuleInfo objList, bool isAdmin, int PackageID, bool IsActive, DateTime AddedOn, int PortalID, string AddedBy)
        {
            string sp = "[dbo].[sp_ModulesAdd]";
            //SQLHandler sagesql = new SQLHandler();
            try
            {
                List<KeyValuePair<string, object>> ParamCollInput = new List<KeyValuePair<string, object>>();
                ParamCollInput.Add(new KeyValuePair<string, object>("@ModuleName", objList.ModuleName));
                ParamCollInput.Add(new KeyValuePair<string, object>("@Name", objList.Name));
                ParamCollInput.Add(new KeyValuePair<string, object>("@FriendlyName", objList.FriendlyName));
                ParamCollInput.Add(new KeyValuePair<string, object>("@Description", objList.Description));
                ParamCollInput.Add(new KeyValuePair<string, object>("@FolderName", objList.FolderName));
                ParamCollInput.Add(new KeyValuePair<string, object>("@Version", objList.Version));

                ParamCollInput.Add(new KeyValuePair<string, object>("@isPremium", objList.isPremium));
                ParamCollInput.Add(new KeyValuePair<string, object>("@isAdmin", isAdmin));


                ParamCollInput.Add(new KeyValuePair<string, object>("@Owner", objList.Owner));
                ParamCollInput.Add(new KeyValuePair<string, object>("@Organization", objList.Organization));
                ParamCollInput.Add(new KeyValuePair<string, object>("@URL", objList.URL));
                ParamCollInput.Add(new KeyValuePair<string, object>("@Email", objList.Email));
                ParamCollInput.Add(new KeyValuePair<string, object>("@ReleaseNotes", objList.ReleaseNotes));
                ParamCollInput.Add(new KeyValuePair<string, object>("@License", objList.License));
                ParamCollInput.Add(new KeyValuePair<string, object>("@PackageType", objList.PackageType));
                ParamCollInput.Add(new KeyValuePair<string, object>("@supportedFeatures", objList.supportedFeatures));
                ParamCollInput.Add(new KeyValuePair<string, object>("@BusinessControllerClass", objList.BusinessControllerClass));
                ParamCollInput.Add(new KeyValuePair<string, object>("@CompatibleVersions", objList.CompatibleVersions));
                ParamCollInput.Add(new KeyValuePair<string, object>("@dependencies", objList.dependencies));
                ParamCollInput.Add(new KeyValuePair<string, object>("@permissions", objList.permissions));

                ParamCollInput.Add(new KeyValuePair<string, object>("@PackageID", PackageID));
                ParamCollInput.Add(new KeyValuePair<string, object>("@IsActive", IsActive));
                ParamCollInput.Add(new KeyValuePair<string, object>("@AddedOn", AddedOn));
                ParamCollInput.Add(new KeyValuePair<string, object>("@PortalID", PortalID));
                ParamCollInput.Add(new KeyValuePair<string, object>("@AddedBy", AddedBy));

                List<KeyValuePair<string, object>> ParamCollOutput = new List<KeyValuePair<string, object>>();
                ParamCollOutput.Add(new KeyValuePair<string, object>("@ModuleID", objList.ModuleID));
                ParamCollOutput.Add(new KeyValuePair<string, object>("@ModuleDefID", objList.ModuleDefID));

                SageFrameSQLHelper sagesql = new SageFrameSQLHelper();

                List<KeyValuePair<int, string>> OutputValColl = new List<KeyValuePair<int, string>>();
                OutputValColl = sagesql.ExecuteNonQueryWithMultipleOutput(sp, ParamCollInput, ParamCollOutput);
                int[] arrOutPutValue = new int[2];
                arrOutPutValue[0] = int.Parse(OutputValColl[0].Value);
                arrOutPutValue[1] = int.Parse(OutputValColl[1].Value);

                return arrOutPutValue;

            }
            catch (Exception)
            {
                throw;
            }
        }
        /// <summary>
        /// Connects to database and adds module permission
        /// </summary>
        /// <param name="ModuleDefID">Module's definition ID.</param>
        /// <param name="PermissionID">Permission ID.</param>
        /// <param name="PortalID">Portal ID.</param>
        /// <param name="PortalModuleID">Portal module ID.</param>
        /// <param name="AllowAccess">Set true if the user is allowed access to this module.</param>
        /// <param name="Username">User's name.</param>
        /// <param name="IsActive">Set true if the permission is active.</param>
        /// <param name="AddedOn">Permission added date</param>
        /// <param name="AddedBy">Permission added user's name.</param>
        /// <returns>Returns array of int containing 1:ModuleDefPermissionID and 2:PortalModulePermissionID.</returns>
        public int[] AddModulePermission(int? ModuleDefID, int? PermissionID, int? PortalID, int? PortalModuleID, bool AllowAccess, string Username, bool IsActive, DateTime AddedOn, string AddedBy)
        {
            string sp = "[dbo].[sp_ModulesPermissionAdd]";
            SQLHandler sagesql = new SQLHandler();
            try
            {
                List<KeyValuePair<string, object>> ParamCollInput = new List<KeyValuePair<string, object>>();
                ParamCollInput.Add(new KeyValuePair<string, object>("@ModuleDefID", ModuleDefID));
                ParamCollInput.Add(new KeyValuePair<string, object>("@PermissionID", PermissionID));
                ParamCollInput.Add(new KeyValuePair<string, object>("@PortalID", PortalID));
                ParamCollInput.Add(new KeyValuePair<string, object>("@PortalModuleID", PortalModuleID));
                ParamCollInput.Add(new KeyValuePair<string, object>("@AllowAccess", AllowAccess));

                ParamCollInput.Add(new KeyValuePair<string, object>("@UserName", Username));
                ParamCollInput.Add(new KeyValuePair<string, object>("@IsActive", IsActive));
                ParamCollInput.Add(new KeyValuePair<string, object>("@AddedOn", AddedOn));
                ParamCollInput.Add(new KeyValuePair<string, object>("@AddedBy", AddedBy));

                //int ListID = sagesql.ExecuteNonQueryAsGivenType<int>(sp, ParamCollInput, "@ModuleDefPermissionID");
                //return ListID;

                ModuleInfo objInfo = new ModuleInfo();
                List<KeyValuePair<string, object>> ParamCollOutput = new List<KeyValuePair<string, object>>();
                ParamCollOutput.Add(new KeyValuePair<string, object>("@ModuleDefPermissionID", objInfo.ModuleDefPermissionID));
                ParamCollOutput.Add(new KeyValuePair<string, object>("@PortalModulePermissionID", objInfo.PortalModulePermissionID));

                SageFrameSQLHelper objHelper = new SageFrameSQLHelper();

                List<KeyValuePair<int, string>> OutputValColl = new List<KeyValuePair<int, string>>();
                OutputValColl = objHelper.ExecuteNonQueryWithMultipleOutput(sp, ParamCollInput, ParamCollOutput);
                int[] arrOutPutValue = new int[2];
                arrOutPutValue[0] = int.Parse(OutputValColl[0].Value);
                arrOutPutValue[1] = int.Parse(OutputValColl[1].Value);

                return arrOutPutValue;
            }
            catch (Exception)
            {
                throw;
            }
        }
        public string AddUserModule(UserModuleInfo module)
        {
            SageFrameSQLHelper sqlH = new SageFrameSQLHelper();
            SqlTransaction tran = (SqlTransaction)sqlH.GetTransaction();
            try
            {
                List<KeyValuePair<string, object>> ParaMeterCollection = new List<KeyValuePair<string, object>>
                                                                            {                                                                              
                                                                                new KeyValuePair<string, object>(
                                                                                    "@ModuleDefID", module.ModuleDefID),
                                                                                new KeyValuePair<string, object>(
                                                                                    "@UserModuleTitle", module.UserModuleTitle),
                                                                                new KeyValuePair<string, object>(
                                                                                    "@AllPages", module.AllPages),
                                                                                new KeyValuePair<string, object>(
                                                                                    "@ShowInPages", module.ShowInPages),
                                                                                new KeyValuePair<string, object>(
                                                                                    "@InheritViewPermissions", module.InheritViewPermissions),
                                                                                new KeyValuePair<string, object>(
                                                                                    "@IsActive", module.IsActive),
                                                                                new KeyValuePair<string, object>(
                                                                                    "@AddedOn", DateTime.Now),
                                                                                new KeyValuePair<string, object>(
                                                                                    "@PortalID", module.PortalID),
                                                                                new KeyValuePair<string, object>(
                                                                                    "@AddedBy", module.PortalID),
                                                                                new KeyValuePair<string, object>(
                                                                                    "@SEOName", module.SEOName),
                                                                                new KeyValuePair<string,object>(
                                                                                    "@IsHandheld",module.IsHandheld),
                                                                                new KeyValuePair<string,object>(
                                                                                    "@SuffixClass",module.SuffixClass),
                                                                                new KeyValuePair<string,object>(
                                                                                    "@HeaderText",module.HeaderText),
                                                                                new KeyValuePair<string,object>(
                                                                                    "@ShowHeaderText",module.ShowHeaderText),
                                                                                new KeyValuePair<string,object>(
                                                                                    "@IsInAdmin",module.IsInAdmin) 
                                                                            };

                List<KeyValuePair<string, object>> ParaMeterInputCollection = new List<KeyValuePair<string, object>>
                                                                            {                                                                              
                                                                                new KeyValuePair<string, object>(
                                                                                    "@UserModuleID", 0),
                                                                                new KeyValuePair<string, object>(
                                                                                    "@ControlCount", 0)                                                                                
                                                                            };


                List<KeyValuePair<int, string>> resultColl = new List<KeyValuePair<int, string>>();
                resultColl = sqlH.ExecuteNonQueryWithMultipleOutput(tran, CommandType.StoredProcedure, "[dbo].[usp_UserModulesAdd]", ParaMeterCollection, ParaMeterInputCollection);
                if (int.Parse(resultColl[0].Value) > 0)
                {
                    if (module.InheritViewPermissions)
                    {
                        //if (module.IsInAdmin)
                        //{
                        //    module.PortalID = -1;
                        //}
                        SetUserModuleInheritedPermission(module.PageID, tran, int.Parse(resultColl[0].Value), module.PortalID, module.AddedBy, module.ModuleDefID);
                    }
                    else
                    {
                        SetUserModulePermission(module.LSTUserModulePermission, tran, int.Parse(resultColl[0].Value), module.PortalID, module.AddedBy, module.ModuleDefID);
                    }
                    if(module.IsInAdmin)
                    {
                        module.PortalID = -1;
                    }
                    SetPageModules(module, tran, int.Parse(resultColl[0].Value), module.PortalID, module.AddedBy);

                }
                tran.Commit();
                return (string.Format("{0}_{1}", resultColl[0].Value.ToString(), resultColl[1].Value.ToString()));

            }
            catch (SqlException sqlEx)
            {
                tran.Rollback();
                throw sqlEx;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }