Exemplo n.º 1
0
        public static Company GetDataForTree()
        {
            context = new CompaniesTreeEntities();

            var mainCompanyFromDB = context.Companies.First(c => c.ID == 25);

            Company mainCompany = new Company();

            mainCompany.ID      = mainCompanyFromDB.ID;
            mainCompany.Name    = mainCompanyFromDB.Name;
            mainCompany.Earning = mainCompanyFromDB.Earning;

            decimal?earningWithChild;

            mainCompany.children         = SearchSubCompanies(mainCompany.ID, out earningWithChild);
            mainCompany.EarningWithChild = mainCompany.Earning + earningWithChild;

            //***BBBBBBBUUUUUUUUUUGGGGGGGGGGGG***

            foreach (var myCompany in mainCompany.children)
            {
                if (context.Companies.Count(c => c.ID == myCompany.ID) > 0)
                {
                    myCompany.children         = SearchSubCompanies(myCompany.ID, out earningWithChild);
                    myCompany.EarningWithChild = myCompany.Earning + earningWithChild;
                }
                foreach (var mySubCompany in myCompany.children)
                {
                    if (context.Companies.Count(c => c.ID == mySubCompany.ID) > 0)
                    {
                        mySubCompany.children         = SearchSubCompanies(mySubCompany.ID, out earningWithChild);
                        mySubCompany.EarningWithChild = mySubCompany.Earning + earningWithChild;
                        mainCompany.EarningWithChild += mySubCompany.EarningWithChild;
                    }
                    foreach (var mySubSubCompany in mySubCompany.children)
                    {
                        if (context.Companies.Count(c => c.ID == mySubSubCompany.ID) > 0)
                        {
                            mySubSubCompany.children         = SearchSubCompanies(mySubSubCompany.ID, out earningWithChild);
                            mySubSubCompany.EarningWithChild = mySubSubCompany.Earning + earningWithChild;
                            myCompany.EarningWithChild      += mySubSubCompany.EarningWithChild;
                        }
                        foreach (var mySubSubSubCompany in mySubSubCompany.children)
                        {
                            if (context.Companies.Count(c => c.ID == mySubSubSubCompany.ID) > 0)
                            {
                                mySubSubSubCompany.children         = SearchSubCompanies(mySubSubSubCompany.ID, out earningWithChild);
                                mySubSubSubCompany.EarningWithChild = mySubSubSubCompany.Earning + earningWithChild;
                                mySubCompany.EarningWithChild      += mySubSubSubCompany.EarningWithChild;
                                myCompany.EarningWithChild         += mySubSubSubCompany.EarningWithChild;
                                mainCompany.EarningWithChild       += mySubSubSubCompany.EarningWithChild;
                            }
                        }
                    }
                }
            }
            return(mainCompany);
        }
Exemplo n.º 2
0
        public static Company EditCompany(Company company)
        {
            context = new CompaniesTreeEntities();
            var companyDB = context.Companies.First(c => c.ID == company.ID);

            companyDB.Earning = company.Earning;
            companyDB.Name    = company.Name;
            context.SaveChanges();
            return(GetDataForTree());
        }
Exemplo n.º 3
0
 public static Company DeleteCompany(int clickedID)
 {
     context = new CompaniesTreeEntities();
     if (clickedID != 25)
     {
         var companyDB = context.Companies.First(c => c.ID == clickedID);
         // RemoveBelonged(clickedID);
         context.Companies.Remove(companyDB);
         context.SaveChanges();
     }
     return(GetDataForTree());
 }
Exemplo n.º 4
0
 public static Company AddNewCompany(Company newCompany)
 {
     context = new CompaniesTreeEntities();
     context.Companies.Add(new Companies()
     {
         Name       = newCompany.Name,
         Earning    = newCompany.Earning,
         BelongToID = newCompany.ID
     });
     context.SaveChanges();
     return(GetDataForTree());
 }