/// <summary> /// getEntityContracts Method used to get all contracts according to contracttypeID for entities records /// </summary> /// <param action="contractTypeID">contractTypeID is used to retreive contracts from DB</param> /// <param action="CultureIdentifier">CultureIdentifier is used to get data according to current culture</param> /// <returns>List of contracts</returns> public static List<TopContractsDAL10.Contract> getEntityContracts(long contractTypeID, string CultureIdentifier, Guid OrganizationIdentifier, int UserID) { List<Contract> contracts = new List<Contract>(); TopContractsV01Entities context = new TopContractsV01Entities(Utilities.getTestEnvName()); List<long> contractIDs = context.Contracts.Where(cnts => cnts.ContractTypeID == contractTypeID).Select(cnt => cnt.ContractID).ToList(); if (contractIDs.Count > 0) { //This flag is used to inform the contract initialization process that many "contracts" (catalog records) //of the same type are now being created, so it needs to avoid re-creating structures which are common //to all these "contracts"... initializingCatalogRecords = true; TopContractsDAL10.Contract.efFieldGroupsForContractInit = null; foreach (long contractID in contractIDs) { //TopContractsDAL10.Contract conts = new Contract(contractID, CultureIdentifier, null, ContractSections.Fields); ContractSectionPaging dontPage = new ContractSectionPaging().SetDontPage(); TopContractsDAL10.Contract conts = new Contract(contractID, CultureIdentifier, dontPage, null, ContractSections.Fields); // Kai Cohen - Modified code to pass paging parameters. -1 tells the method to bring all records. contracts.Add(conts); } initializingCatalogRecords = false; } else { TopContractsDAL10.Contract conts = new Contract(OrganizationIdentifier, "", contractTypeID, 1, UserID, CultureIdentifier); // 1 is used for default status ID (HardCoded) and "" foe Contractname contracts.Add(conts); } return contracts; }
/// <summary> /// This constructor is only used to fetch an existing contract, and not for creating a new one. /// </summary> /// <param action="ContractID">ID of contract to fetch</param> /// <param action="CultureIdentifier">Culture Identifier used for the selection of Fields and Field-Groups /// names in the appropriate language.</param> /// <param name="paging">Object of ContractSectionPaging class to provide page sizes of various contract sections.</param> /// <param action="UserId">UserID may be passed to set the read-only value of RoleName of that user /// in the selected contract</param> public Contract(long ContractID, string CultureIdentifier, ContractSectionPaging paging, long? UserId = null, ContractSections Content = ContractSections.All, List<long> GroupIDs = null) { Logger.WriteGeneralVerbose("Contract class - CTOR 2", "Commencing CTOR for ContractID {0}, UserId {1}, Content {2}", ContractID, UserId, Content.ToString()); //ErrorDTO Error = null; //try //{ Deleted = false; Properties = new ContractProperties(); initLists(); Logger.WriteGeneralVerbose("Contract class - CTOR 2", "Lists initialized"); TopContractsV01Entities context = new TopContractsV01Entities(Utilities.getTestEnvName()); TopContractsEntities.Contract efContract = context.Contracts.Where(u => u.ContractID == ContractID).SingleOrDefault(); this.ID = efContract.ContractID; this.Properties.initDataFields(efContract); Logger.WriteGeneralVerbose("Contract class - CTOR 2", "Data Fields initialized"); this.Properties.initPrivateFields(efContract, CultureIdentifier, UserId); Logger.WriteGeneralVerbose("Contract class - CTOR 2", "Private Fields initialized"); if ((Content & ContractSections.Events) == ContractSections.Events) { this.ContractActivities.AddRange(efContract.ContractActivities.Select(ca => new ContractActivity(ca, CultureIdentifier))); Logger.WriteGeneralVerbose("Contract class - CTOR 2", "Events added for ContractSections.Events"); } if ((Content & ContractSections.Alerts) == ContractSections.Alerts) { this.ContractTodos.AddRange(efContract.ContractTodos.Select(ca => new ContractTodo(ca, CultureIdentifier))); Logger.WriteGeneralVerbose("Contract class - CTOR 2", "Alerts added for ContractSections.Alerts"); } if ((Content & ContractSections.AuthorizedEntities) == ContractSections.AuthorizedEntities) { bool showAllUser = false; long? MaxPageSizeUsers = null; if (paging.UsersPaging.PagingBehaviour == PagingParameter.DontPage) showAllUser = true; else if (paging.UsersPaging.PagingBehaviour == PagingParameter.OverrideDatabaseValues) MaxPageSizeUsers = paging.UsersPaging.PagingValue; else MaxPageSizeUsers = GetPagingValueFromDB(efContract.OrganizationIdentifier, ContractSections.AuthorizedEntities); if (showAllUser == true || MaxPageSizeUsers == null) this.ContractUsers.AddRange(efContract.ContractUsers.Select(ca => new ContractUser(ca, CultureIdentifier))); else this.ContractUsers.AddRange(GetContractUsersByPaging(ContractID, CultureIdentifier, Convert.ToInt64(MaxPageSizeUsers))); Logger.WriteGeneralVerbose("Contract class - CTOR 2", "Users added for ContractSections.AuthorizedEntities"); } if ((Content & ContractSections.Applications) == ContractSections.Applications) { this.ContractApplications.AddRange(efContract.ContractApplications.Select(ca => new ContractApplication(ca))); Logger.WriteGeneralVerbose("Contract class - CTOR 2", "Applications added for ContractSections.Applications"); } if ((Content & ContractSections.Fields) == ContractSections.Fields) { //Code Commented By Viplav for implement sorting related to (DisplayOrder / Alphabatically) //long groupID = 0; //foreach (TopContractsEntities.ContractField field in efContract.ContractFields.OrderBy(fl => fl.FieldGroupID)) //{ // if (field.FieldGroupID != groupID) // { // groupID = field.FieldGroupID; // this.ContractFieldGroups.Add(new ContractFieldGroup(field, CultureIdentifier)); // } //} //Viplav //------------Boaz 25-July-2013------------- //If this "contract" is a catalog record, and it is now fetched as part of a process of //fetching many such catalog records of the same type, then groupFields collection should //be initialized only once... List<FieldGroup> efFieldGroups = null; if (Contract.initializingCatalogRecords == false || Contract.efFieldGroupsForContractInit == null) { efFieldGroups = new List<FieldGroup>(); //if (efContract.ContractFields.Any(fg => fg.FieldGroup.DisplayOrder == null)) //{ // efFieldGroups = efContract.ContractFields.Select(fg => fg.FieldGroup).Distinct().OrderBy(fgl => fgl.FieldGroupsLNGs.FirstOrDefault(cul => cul.CultureId.Trim() == CultureIdentifier).DescShort).ToList(); //} //else //{ // efFieldGroups = efContract.ContractFields.Select(fg => fg.FieldGroup).Distinct().OrderBy(fgd => fgd.DisplayOrder).ToList(); //} //List<ContractTypeFieldGroupsMap> groupsMap = new List<ContractTypeFieldGroupsMap>(); //groupsMap = ApplicationCachedData.ContractTypeFieldGroupsMap; if (efContract.ContractType.ParentContractTypeID == Utilities.contractTypeContractsID) { if (ApplicationCachedData.ContractTypeFieldGroupsMap.Any(ct => ct.ContractTypeID == efContract.ContractTypeID)) { Dictionary<string, List<FieldGroup>> FieldGroupsByLang = ApplicationCachedData.ContractTypeFieldGroupsMap.Single(ct => ct.ContractTypeID == efContract.ContractTypeID).FieldGroupsByLang; if (FieldGroupsByLang.Count() > 0) if (FieldGroupsByLang.Any(lng => lng.Key == CultureIdentifier)) efFieldGroups = FieldGroupsByLang.Single(lng => lng.Key == CultureIdentifier).Value; } } else { if (ApplicationCachedData.CatalogFieldGroupsMap.Any(ct => ct.ContractTypeID == efContract.ContractTypeID)) { Dictionary<string, List<FieldGroup>> FieldGroupsByLang = ApplicationCachedData.CatalogFieldGroupsMap.Single(ct => ct.ContractTypeID == efContract.ContractTypeID).FieldGroupsByLang; if (FieldGroupsByLang.Count() > 0) if (FieldGroupsByLang.Any(lng => lng.Key == CultureIdentifier)) efFieldGroups = FieldGroupsByLang.Single(lng => lng.Key == CultureIdentifier).Value; } } Contract.efFieldGroupsForContractInit = efFieldGroups; } else efFieldGroups = Contract.efFieldGroupsForContractInit; // if list of GroupIDs is not null if (GroupIDs != null) { if (GroupIDs.Count() > 0) { // retrieve only those fieldgroups which are requested. efFieldGroups = efFieldGroups.Where(fg => GroupIDs.Contains(fg.FieldGroupID)).ToList(); } } foreach (FieldGroup fieldgroup in efFieldGroups) { this.ContractFieldGroups.Add(new ContractFieldGroup(context, fieldgroup, CultureIdentifier, ContractID)); } Logger.WriteGeneralVerbose("Contract class - CTOR 2", "Fields added for ContractSections.Fields"); } if ((Content & ContractSections.Documents) == ContractSections.Documents) { this.ContractDocs.AddRange(efContract.ContractDocs.Select(ca => new ContractDoc(ca))); Logger.WriteGeneralVerbose("Contract class - CTOR 2", "Documents added for ContractSections.Documents"); } if ((Content & ContractSections.Gallery) == ContractSections.Gallery) { this.ContractGalleries.AddRange(efContract.ContractGalleries.OrderByDescending(cg => cg.CreatedOn).Select(cg => new ContractGallery(cg))); Logger.WriteGeneralVerbose("Contract class - CTOR 2", "Galleries added for ContractSections.Gallery"); } if ((Content & ContractSections.ChildContract) == ContractSections.ChildContract) // Condition Implemented for getting only neccessary Data by Viplav on 14 May 2013 { this.ChildContracts = new ChildContract(ref context, efContract).ChildContracts; Logger.WriteGeneralVerbose("Contract class - CTOR 2", "Child Contracts collection initialized"); } if ((Content & ContractSections.ParantContract) == ContractSections.ParantContract) // Condition Implemented for getting only neccessary Data by Viplav on 14 May 2013 { if (efContract.ParentContractID != null) { //this.ParentContract = new Contract((long)efContract.ParentContractID, CultureIdentifier, UserId, Content); this.ParentContract = new Contract((long)efContract.ParentContractID, CultureIdentifier, paging, UserId, Content); // Kai Cohen - Modified code to pass paging parameters. Logger.WriteGeneralVerbose("Contract class - CTOR 2", "Parent Contracts initialized"); } } }