/// <summary>
        /// This constructor is ONLY used for creating new contracts, not for getting information about existing contracts.
        /// </summary>
        /// <param action="ContractName">The action for the new contract being created</param>
        /// <param action="ContractTypeID">The type for the new contract being created</param>
        /// <param action="ContractStatusID">The status for the new contract being created</param>
        /// <param action="UserIdCreator">The ID of the user creating the contract</param>
        /// <param action="CultureIdentifier">Culture Identifier used for the selection of Fields and Field-Groups 
        /// names in the appropriate language, in the process of creating those for the contract. The language
        /// is not needed for the creation, so much as it is needed for the population of data in the newly created contract</param>
        public Contract(Guid OrganizationIdentifier, string ContractName, long ContractTypeID, long? ContractStatusID, long UserIdCreator, string CultureIdentifier, long RoleID = 0)
        {
            //int RoleIdCreator = (int)SpecialRoles.OwnerRoleID; //Always the "owner" is the one creating the contracts...
            long RoleIdCreator = RoleID; //RoleID is a default userid used for contractuser table
            try
            {
                Deleted = false;
                Properties = new ContractProperties();
                initLists();

                New = true;
                Properties.Name = ContractName;
                Properties.ContractTypeID = ContractTypeID;
                Properties.StatusID = (int?)ContractStatusID;
                Properties.OrganizationIdentifier = OrganizationIdentifier;

                ContractUsers.Add(new ContractUser() { New = true, EntryId = UserIdCreator, RoleID = RoleIdCreator });

                TopContractsV01Entities context = new TopContractsV01Entities(Utilities.getTestEnvName());
                //long ContractTypeContractsID = ConfigurationProvider.Default.ContractTypeContracts.ContractTypeContractsID;
                long ContractTypeContractsID = Utilities.contractTypeContractsID; // Code implemented by Viplav on 17 june 2013 for remove webconfig concept
                TopContractsDAL10.SystemTables.FieldGroups fieldGroups = new SystemTables.FieldGroups();
                if (context.ContractTypes.Any(ct => ct.ParentContractTypeID == ContractTypeContractsID && ct.ContractTypeID == ContractTypeID))
                    fieldGroups = SystemTables.FieldGroups.Get(false, false, true, CultureIdentifier);
                else
                    fieldGroups = SystemTables.FieldGroups.GetWithoutParentContractTypeID(false, false, true, CultureIdentifier);

                string logData1 = "FieldGroups created: " + Environment.NewLine;
                foreach (TopContractsDAL10.SystemTables.FieldGroup fGrp in fieldGroups.Entries)
                {
                    logData1 = logData1 + string.Format("FieldGroup info: groupID-{0}", fGrp.ID) + Environment.NewLine;
                }
                Logger.WriteGeneralVerbose("Contract class - CTOR", logData1);

                Logger.WriteGeneralVerbose("Contract class - CTOR", "Creating FieldGroups collection");
                foreach (TopContractsDAL10.SystemTables.FieldGroup fieldGroup in fieldGroups.Entries)
                {
                    //if (fieldGroup.ContractTypeIDsVisible.Any(ct => ct == ContractTypeID)) //Boaz - 7-Aug-2012
                    if (context.ContractTypes.Any(ct => ct.ParentContractTypeID == ContractTypeContractsID && ct.ContractTypeID == ContractTypeID))
                    {
                        if (fieldGroup.ContractTypeIDsVisible.Any(ct => ct == ContractTypeID) || fieldGroup.VisibleToAllContractTypes)
                            ContractFieldGroups.Add(new ContractFieldGroup(fieldGroup, CultureIdentifier));
                    }
                    else
                    {
                        if (fieldGroup.ContractTypeIDsVisible.Any(ct => ct == ContractTypeID))
                            ContractFieldGroups.Add(new ContractFieldGroup(fieldGroup, CultureIdentifier));
                    }
                }
                string logData2 = "ContractFieldGroups created: " + Environment.NewLine;
                foreach (ContractFieldGroup cFldGrp in ContractFieldGroups)
                {
                    logData2 = logData2 + string.Format("FieldGroup info: groupID-{0}", cFldGrp.EntryId) + Environment.NewLine;
                }
                Logger.WriteGeneralVerbose("Contract class - CTOR", logData2);
            }
            catch (Exception ex)
            {
                Logger.WriteExceptionError("Contract class - Contract", ex);
                ErrorDTO Error = new ErrorDTO(new ExceptionUnknownContractInit(ex));
            }
        }
        //end code
        /// <summary>--Added by Viplav Bhateja (28/02/2013)
        /// Used to get only common field group (this functionality is used for copy contract when user change his current contract type))
        /// </summary>
        /// <param action="ContractTypeID">Contract TypeID is used to get contractfieldgroup according to this contract type.</param>
        /// <param action="ContractToSave">Contract to save is an existing loaded contract so we can inplement a functionality to add only common field group.</param>
        /// <param action="CultureIdentifier">Culture Identifier used for the selection of Fields and Field-Groups 
        /// names in the appropriate language.</param>
        /// <returns></returns>
        public static List<int> getCommonContractFieldGroup(int parentContractTypeID, int childContractTypeID, string CultureIdentifier)
        {
            TopContractsV01Entities context = new TopContractsV01Entities(Utilities.getTestEnvName());
            //long ContractTypeContractsID = ConfigurationProvider.Default.ContractTypeContracts.ContractTypeContractsID;
            long ContractTypeContractsID = Utilities.contractTypeContractsID; // Code implemented by Viplav on 17 june 2013 for remove webconfig concept
            TopContractsDAL10.SystemTables.FieldGroups fieldGroups = new SystemTables.FieldGroups();
            List<int> parentFieldGroupIDs = new List<int>();
            List<int> childFieldGroupIDs = new List<int>();
            List<int> commonFieldGroupIDs = new List<int>();
            if (context.ContractTypes.Any(ct => ct.ParentContractTypeID == ContractTypeContractsID && ct.ContractTypeID == parentContractTypeID))
                fieldGroups = SystemTables.FieldGroups.Get(false, false, true, CultureIdentifier);
            else
                fieldGroups = SystemTables.FieldGroups.GetWithoutParentContractTypeID(false, false, true, CultureIdentifier);

            foreach (TopContractsDAL10.SystemTables.FieldGroup fieldGroup in fieldGroups.Entries)
            {
                if (context.ContractTypes.Any(ct => ct.ParentContractTypeID == ContractTypeContractsID && ct.ContractTypeID == parentContractTypeID))
                {
                    if (fieldGroup.ContractTypeIDsVisible.Any(ct => ct == parentContractTypeID) || fieldGroup.VisibleToAllContractTypes)
                        parentFieldGroupIDs.Add((int)fieldGroup.ID);
                }
            }
            foreach (TopContractsDAL10.SystemTables.FieldGroup fieldGroup in fieldGroups.Entries)
            {
                if (context.ContractTypes.Any(ct => ct.ParentContractTypeID == ContractTypeContractsID && ct.ContractTypeID == childContractTypeID))
                {
                    if (fieldGroup.ContractTypeIDsVisible.Any(ct => ct == childContractTypeID) || fieldGroup.VisibleToAllContractTypes)
                        childFieldGroupIDs.Add((int)fieldGroup.ID);
                }
            }
            foreach (int cfg in childFieldGroupIDs)
            {
                if (parentFieldGroupIDs.Any(ctrgroup => ctrgroup == cfg))
                {
                    commonFieldGroupIDs.Add(cfg);
                }
            }
            return commonFieldGroupIDs;
        }
 /// <summary>
 /// Used to save Field Group Role Map when limited Role entered in Role Table
 /// </summary>
 public void SaveFieldGroupsRolesMAPforLimitedUser()
 {
     TopContractsV01Entities context = new TopContractsV01Entities(Utilities.getTestEnvName()); ;
     TopContractsDAL10.SystemTables.FieldGroups fieldGroups = new SystemTables.FieldGroups();
     foreach (TopContractsEntities.FieldGroup fldGrp in context.FieldGroups.Where(fld => fld.RolesVisibility == (byte)FieldGroupRoleVisibility.VisibleToAll))
     {
         fldGrp.RolesVisibility = (byte)FieldGroupRoleVisibility.VisibleToRoles;
         //Adding entries in FieldGroupsRolesMAP according to roles and efFieldGroupsForContractInit
         foreach (TopContractsEntities.Role role in context.Roles.Where(rl => rl.EditFields == null || rl.EditFields == false))
         {
             fldGrp.FieldGroupsRolesMAPs.Add(new FieldGroupsRolesMAP() { OrganizationIdentifier = this.organizationIdentifier, RoleID = role.RoleID, FieldGroupID = fldGrp.FieldGroupID, AllowView = true, AllowEdit = true });
         }
     }
     context.SaveChanges();
 }