Example #1
0
        public static List <Company> GetParentCompaniesForAssureurIdORIG(int assurId)
        {
            try
            {
                List <Company> companies;
                Assureur       assur = Assureur.GetAssById(assurId);

                using (var context = new CompteResultatEntities())
                {
                    List <int> listOfContractIds = assur.Contracts.Select(c => c.Id).ToList();

                    companies = context.Companies.Where(c => (c.ParentId == null &&
                                                              listOfContractIds.Intersect(c.Contracts.Select(cont => cont.Id).ToList()).Any())).OrderBy(c => c.Name).ToList();
                }

                if (companies == null)
                {
                    throw new Exception("The 'Company' entity does not contain any data!");
                }

                return(companies);
            }
            catch (Exception ex)
            {
                log.Error(ex.Message);
                throw ex;
            }
        }
Example #2
0
        //####

        public static List <string> GetParentCompanyNamesForAssureurId(int assurId)
        {
            try
            {
                List <Company> parentComps;
                List <string>  companies = new List <string>();
                Assureur       assur     = Assureur.GetAssById(assurId);

                using (var context = new CompteResultatEntities())
                {
                    List <int> listOfContractIds = assur.Contracts.Select(c => c.Id).ToList();

                    //use eager loading to get contract data related to each company
                    parentComps = context.Companies
                                  .Where(c => (c.ParentId == null))
                                  .Include(c => c.Contracts)
                                  .OrderBy(c => c.Name)
                                  .ToList();


                    foreach (Company c in parentComps)
                    {
                        bool hasCommonContracts = listOfContractIds.Intersect(c.Contracts.Select(cont => cont.Id).ToList()).Any();
                        if (hasCommonContracts)
                        {
                            companies.Add(c.Name);
                        }
                    }

                    //companies = context.Companies.Where(c => (c.ParentId == null &&
                    //    listOfContractIds.Intersect(c.Contracts.Select(cont => cont.Id).ToList()).Any()  ) )
                    //    .OrderBy(c => c.Name).ToList();
                }

                if (companies == null)
                {
                    throw new Exception("The 'Company' entity does not contain any data!");
                }

                return(companies);
            }
            catch (Exception ex)
            {
                log.Error(ex.Message);
                throw ex;
            }
        }