/// <summary> /// Gets page size value from the AppSettings table in the database. /// </summary> /// <param name="OrganizationIdentifier">ID of the Orgainzation whose paging size is required.</param> /// <param name="contractSection">Contract section whose paging size is required.</param> /// <returns>An integer value. Can also be null.</returns> public long? GetPagingValueFromDB(Guid OrganizationIdentifier, ContractSections contractSection) { TopContractsV01Entities context = new TopContractsV01Entities(Utilities.getTestEnvName()); long? PageSize = null; if (context.AppSettings.Any(org => org.OrganizationIdentifier == OrganizationIdentifier)) { AppSetting efAppSettings = context.AppSettings.SingleOrDefault(org => org.OrganizationIdentifier == OrganizationIdentifier); switch (contractSection) { case ContractSections.AuthorizedEntities: PageSize = efAppSettings.MaxPageSizeUsers; break; case ContractSections.Documents: PageSize = efAppSettings.MaxPageSizeDocs; break; case ContractSections.Events: PageSize = efAppSettings.MaxPageSizeEvents; break; case ContractSections.Gallery: PageSize = efAppSettings.MaxPageSizeGalleries; break; default: break; } } return PageSize; }
/// <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"); } } }