Ejemplo n.º 1
0
        public ActionResult GetTree()
        {
            var ctvm = new CompanyTreeViewModel();
            var role_building_ids = GetUserBuildings(_buildingRepository, _userRepository);

            ctvm.Countries =
                from country in _countryRepository.FindAll(x => !x.IsDeleted)
                select
                new Node
            {
                ParentId = 0,
                MyId     = country.Id,
                Name     = country.Name
            };

            ctvm.Towns =
                from town in _locationRepository.FindAll(x => !x.IsDeleted)
                select
                new Node
            {
                ParentId = town.CountryId,
                MyId     = town.Id,
                Name     = town.Name
            };

            ctvm.Offices =
                from office in _buildingRepository.FindAll(x => !x.IsDeleted && role_building_ids.Contains(x.Id))
                select
                new Node
            {
                ParentId = office.LocationId,
                MyId     = office.Id,
                Name     = office.Name
            };

            if (CurrentUser.Get().IsBuildingAdmin || CurrentUser.Get().IsCompanyManager)
            {
                ctvm.Offices   = role_building_ids.Count > 0 ? ctvm.Offices.Where(build => role_building_ids.Contains(build.MyId)).ToList() : new List <Node>();
                ctvm.Towns     = ctvm.Towns.Where(town => ctvm.Offices.Any(off => off.ParentId == town.MyId));
                ctvm.Countries = ctvm.Countries.Where(country => ctvm.Towns.Any(town => town.ParentId == country.MyId));
            }

            List <int> companyIds =
                (from c in _companyRepository.FindAll(x => !x.IsDeleted && x.Active && x.ParentId == null) select c.Id).ToList();

            ctvm.Companies =
                from company in
                _companyBuildingObjectRepository.FindAll(x => !x.IsDeleted && companyIds.Contains(x.CompanyId))
                select
                new Node
            {
                ParentId = company.BuildingObject.BuildingId,
                MyId     = company.Company.Id,
                Name     = company.Company.Name
            };

            ctvm.Companies = ctvm.Companies.Distinct(new NodeEqualityComparer());

            ctvm.Partners =
                from company in
                _companyRepository.FindAll(x => !x.IsDeleted && x.ParentId != null)
                select
                new Node
            {
                ParentId = company.ParentId.Value,
                MyId     = company.Id,
                Name     = company.Name
            };

            ctvm.Partners = ctvm.Partners.Distinct(new NodeEqualityComparer());
            return(PartialView("CompanyTree", ctvm));
        }
Ejemplo n.º 2
0
        public ActionResult Camera()
        {
            var ctvm = new CompanyTreeViewModel();
            var role_building_ids = GetUserBuildings(_buildingRepository, _userRepository, CurrentUser.Get().Id);

            ctvm.Countries =
                from country in _countryRepository.FindAll()
                select
                new Node
            {
                ParentId = 0,
                MyId     = country.Id,
                Name     = country.Name
            };

            ctvm.Towns =
                from town in _locationRepository.FindAll(x => !x.IsDeleted)
                select
                new Node
            {
                ParentId = town.CountryId,
                MyId     = town.Id,
                Name     = town.Name
            };

            //offices is buildings
            ctvm.Offices =
                from office in _buildingRepository.FindAll(x => !x.IsDeleted && role_building_ids.Contains(x.Id))
                select
                new Node
            {
                ParentId = office.LocationId,
                MyId     = office.Id,
                Name     = office.Name
            };


            ctvm.Towns     = ctvm.Towns.Where(town => ctvm.Offices.Any(off => off.ParentId == town.MyId));
            ctvm.Countries = ctvm.Countries.Where(country => ctvm.Towns.Any(town => town.ParentId == country.MyId));

            List <int> companyIds = (from c in _companyRepository.FindAll(x => !x.IsDeleted && x.ParentId == null && x.Active) select c.Id).ToList();

            if (CurrentUser.Get().IsCompanyManager)
            {
                int?companyId = CurrentUser.Get().CompanyId;
                companyIds = (from c in _companyRepository.FindAll(c => !c.IsDeleted && c.Active && (c.Id == companyId || c.ParentId == companyId)) select c.Id).ToList();
            }

            ctvm.Companies =
                from company in
                _companyBuildingObjectRepository.FindAll(x => !x.IsDeleted && companyIds.Contains(x.CompanyId))
                select
                new Node
            {
                ParentId = company.BuildingObject.BuildingId,
                MyId     = company.CompanyId,
                Name     = company.Company.Name
            };

            ctvm.Companies = ctvm.Companies.Distinct(new NodeEqualityComparer());

            ctvm.Partners =
                from partner in
                _companyRepository.FindAll(x => !x.IsDeleted && x.ParentId != null && companyIds.Contains(x.ParentId.Value))
                select
                new Node
            {
                ParentId = partner.ParentId.Value,
                MyId     = partner.Id,
                Name     = partner.Name
            };

            List <Node> Cameras = new List <Node>();
            string      query   = @"select FSC.Name as CameraName , FSC.Id,cmpbo.CompanyId from CompanyBuildingObjects as cmpbo inner join FSBuildingObjectCameras fsboc on cmpbo.BuildingObjectId= fsboc.BuildingObjectId inner join FSCameras FSC ON FSBOC.CameraId= FSC.Id ";
            var         Camera  = db.Database.SqlQuery <CameraDetals>(query);

            foreach (var items1 in Camera)
            {
                Cameras.Add(new Node()
                {
                    ParentId = items1.CompanyId, MyId = items1.Id, Name = items1.CameraName
                });
            }
            ctvm.Cameras = Cameras;
            //ctvm.Cameras =
            //           from Camera in
            //               _IVideoAccessRepository.FindAll(x => companyIds.Contains(Convert.ToInt32(x.CompanyId)))
            //           select
            //               new Node
            //               {
            //                   ParentId = Camera.CompanyId,
            //                   MyId = Camera.Id,
            //                   Name = Camera.CameraName
            //               };
            return(PartialView("Camera", ctvm));
        }
Ejemplo n.º 3
0
        public ActionResult GetTree()
        {
            var ctvm = new CompanyTreeViewModel();
            var role_building_ids = GetUserBuildings(_buildingRepository, _userRepository, CurrentUser.Get().Id);

            ctvm.Countries =
                from country in _countryRepository.FindAll()
                select
                new Node
            {
                ParentId = 0,
                MyId     = country.Id,
                Name     = country.Name
            };

            ctvm.Towns =
                from town in _locationRepository.FindAll(x => !x.IsDeleted)
                select
                new Node
            {
                ParentId = town.CountryId,
                MyId     = town.Id,
                Name     = town.Name
            };

            ctvm.Offices =
                from office in _buildingRepository.FindAll(x => !x.IsDeleted && role_building_ids.Contains(x.Id))
                select
                new Node
            {
                ParentId = office.LocationId,
                MyId     = office.Id,
                Name     = office.Name
            };

            ctvm.Towns     = ctvm.Towns.Where(town => ctvm.Offices.Any(off => off.ParentId == town.MyId));
            ctvm.Countries = ctvm.Countries.Where(country => ctvm.Towns.Any(town => town.ParentId == country.MyId));

            List <int> companyIds = (from c in _companyRepository.FindAll(x => !x.IsDeleted && x.ParentId == null && x.Active) select c.Id).ToList();

            if (CurrentUser.Get().IsCompanyManager)
            {
                int?companyId = CurrentUser.Get().CompanyId;
                companyIds = (from c in _companyRepository.FindAll(c => !c.IsDeleted && c.Active && (c.Id == companyId || c.ParentId == companyId)) select c.Id).ToList();
            }

            ctvm.Companies =
                from company in
                _companyBuildingObjectRepository.FindAll(x => !x.IsDeleted && companyIds.Contains(x.CompanyId))
                select
                new Node
            {
                ParentId = company.BuildingObject.BuildingId,
                MyId     = company.CompanyId,
                Name     = company.Company.Name
            };

            ctvm.Companies = ctvm.Companies.Distinct(new NodeEqualityComparer());

            ctvm.Partners =
                from partner in
                _companyRepository.FindAll(x => !x.IsDeleted && x.ParentId != null && companyIds.Contains(x.ParentId.Value))
                select
                new Node
            {
                ParentId = partner.ParentId.Value,
                MyId     = partner.Id,
                Name     = partner.Name
            };

            ctvm.Floors =
                from floor in
                _companyBuildingObjectRepository.FindAll(x => !x.IsDeleted && companyIds.Contains(x.CompanyId) && x.BuildingObject.TypeId == 1)
                select
                new Node
            {
                ParentId   = floor.CompanyId,
                MyId       = floor.Id,
                Name       = floor.BuildingObject.Description,
                BuildingId = floor.BuildingObject.BuildingId
            };

            return(PartialView("UserTree", ctvm));
        }