Ejemplo n.º 1
0
        public int CreateOrFindBuildingFloorId(int buildingId, int floorNr, string description, int?objectNr = null)
        {
            int result = 0;

            using (IUnitOfWork work = UnitOfWork.Begin())
            {
                var floor = _buildingObjectRepository.FindAll(x => !x.IsDeleted && x.BuildingId == buildingId && x.TypeId == (int)BuildingObjectTypes.Floor && x.FloorNr == floorNr);

                if (floor.Count() == 0)
                {
                    BuildingObject bObject = DomainObjectFactory.CreateBuildingObject();

                    bObject.TypeId      = (int)BuildingObjectTypes.Floor;
                    bObject.BuildingId  = buildingId;
                    bObject.FloorNr     = floorNr;
                    bObject.Description = description;
                    bObject.IsDeleted   = false;
                    bObject.ObjectNr    = objectNr;

                    _buildingObjectRepository.Add(bObject);
                    work.Commit();

                    result = bObject.Id;
                }
                else
                {
                    result = floor.FirstOrDefault().Id;
                }
            }

            return(result);
        }
Ejemplo n.º 2
0
        public ActionResult Edit(int id)
        {
            TerminalModel tm = new TerminalModel();

            var terminal_list = db.Database.SqlQuery <Terminal>("Select * from Terminal where Id=" + id).SingleOrDefault();

            tm.term = terminal_list;

            SelectListItem item = new SelectListItem();

            item.Value = "";
            item.Text  = "--Select--";

            SelectList complist = new SelectList(_companyRepository.FindAll().Where(x => !x.IsDeleted && x.Active).OrderBy(s => s.Name), "Id", "Name", tm.term.CompanyId);

            tm.companies = CardController.AddFirstItem(complist, item);


            SelectListItem item1 = new SelectListItem();

            item1.Value = "";
            item1.Text  = "--Select--";

            SelectList tabuildinglist = new SelectList(_BuildingObjectRepository.FindAll(x => (x.TypeId == 8 || x.TypeId == 1) && !x.IsDeleted), "Id", "Description", tm.term.TARegisterBoId);

            tm.TABuildingList = CardController.AddFirstItem(tabuildinglist, item1);

            return(PartialView("Edit", tm));
        }
Ejemplo n.º 3
0
        public int gettotalcount(string type, int legal)
        {
            int tc  = 0;
            int tc1 = 0;

            if (type == "Users")
            {
                tc1 = _userRepository.FindAll(x => !x.IsDeleted && x.Active == true).ToList().Count();
            }
            if (type == "Doors")
            {
                tc1 = _buildingObjectRepository.FindAll(x => !x.IsDeleted && (x.TypeId == 8 || x.TypeId == 9)).ToList().Count();
            }
            if (type == "Visitors")
            {
                //tc1 = _userRepository.FindAll(x => !x.IsDeleted && x.Active == true && (x.IsShortTermVisitor == true || x.IsVisitor == true)).ToList().Count();
                tc1 = _visitorRepository.FindAll(x => !x.IsDeleted && x.StopDateTime > DateTime.Now).ToList().Count();
            }
            if (type == "Video")
            {
                tc1 = db.FSCameras.Where(x => x.Deleted == false && x.Port > 0).Select(x => x.Id).ToList().Count();
            }
            if (type == "Terminals")
            {
                //tc1 = db._Terminal.Where(x => x.IsDeleted == false && x.ApprovedDevice == true).Select(x => x.Id).ToList().Count();
                tc1 = db.Database.SqlQuery <Terminal>("Select * from Terminal where IsDeleted=0 and ApprovedDevice=1").ToList().Count();
            }
            if (type == "Zones")
            {
                tc1 = _buildingObjectRepository.FindAll(x => !x.IsDeleted && x.TypeId == 10).ToList().Count();
            }
            if (type == "TimeAndAttendense")
            {
                tc1 = db.TABuildingName.Where(x => !x.IsDeleted).ToList().Count();
            }
            if (type == "Companies")
            {
                con.Open();
                SqlCommand cmd = new SqlCommand("select count(distinct CompanyId) from users where IsDeleted=0 and CompanyId is not null and id in (select UserId from uSERROLES where IsDeleted=0 and RoleId in (select id from Roles where IsDeleted=0 and RoleTypeId=3))", con);
                tc1 = Convert.ToInt32(cmd.ExecuteScalar());
                con.Close();
            }
            tc = legal - tc1;
            tc = tc < 0 ? 0 : tc;
            return(tc);
        }
Ejemplo n.º 4
0
        public CompanyBuildingItem GetFloorItems(int?buildingId, int?companyId)
        {
            var building        = _buildingRepository.FindById(buildingId.Value);
            var building_ids    = GetUserBuildings(_buildingRepository, _userRepository);
            var buildingObjects =
                _buildingObjectRepository.FindAll().Where(x => !x.IsDeleted && x.BuildingId == buildingId && x.TypeId == 1);

            var result = new CompanyBuildingItem()
            {
                BuildingId   = buildingId,
                IsAvailable  = building_ids.Contains(buildingId.Value),
                BuildingName = building.Name
            };

            var floors = new List <CompanyFloorItem>();
            var companyBuildingObjects = companyId == null
                                             ? null
                                             : _companyBuildingObjectRepository.FindAll().Where(
                x => x.CompanyId == companyId.Value && x.BuildingObject.BuildingId == buildingId.Value);

            foreach (var buildingObject in buildingObjects)
            {
                var item = new CompanyFloorItem();
                item.CompanyId        = companyId;
                item.BuildingObjectId = buildingObject.Id;
                item.IsAvailable      = building_ids.Contains(buildingObject.BuildingId);
                var cbo = companyBuildingObjects == null ? null : companyBuildingObjects.Where(x => x.BuildingObjectId == buildingObject.Id).FirstOrDefault();
                if (cbo == null)
                {
                    item.IsSelected = false;
                    item.Id         = null;
                }
                else
                {
                    item.IsSelected = !cbo.IsDeleted;
                    item.Id         = cbo.Id;
                }
                floors.Add(item);
            }
            result.CompanyFloors = floors;
            return(result);
        }
Ejemplo n.º 5
0
        public ActionResult GetTree(int? id)
        {
            var ctvm = CreateViewModel<PermissionTreeViewModel>();
            var role_buildingIds = GetUserBuildings(_buildingRepository, _userRepository, CurrentUser.Get().Id);
            if (CurrentUser.Get().IsCompanyManager || CurrentUser.Get().IsCommonUser)
            {
                UserPermissionGroup upg;
                /*
            	var activeUpg =
            		_userPermissionGroupRepository.FindAll().Where(
            			x => x.PermissionIsActive && !x.IsDeleted && x.UserId == CurrentUser.Get().Id).FirstOrDefault();
                */
                var activeUpg =
                _userPermissionGroupRepository.FindByUserId(CurrentUser.Get().Id).Where(
                    x => x.PermissionIsActive && !x.IsDeleted).FirstOrDefault();
                var activeUpgBuildingIds = activeUpg != null ? (from cbo in activeUpg.UserPermissionGroupTimeZones.Where(x => !x.IsDeleted && x.Active) select cbo.BuildingObjectId).ToList() : null;
                if (id.HasValue)
                {
                    upg = _userPermissionGroupRepository.FindById(id.Value);
                    //var cupg = _userPermissionGroupRepository.FindAll(x => x.ParentUserPermissionGroupId == id && x.UserId == CurrentUser.Get().Id);
                    var cupg = _userPermissionGroupRepository.FindByUserId(CurrentUser.Get().Id).Where(x => x.ParentUserPermissionGroupId == id);
                    if (CurrentUser.Get().IsCompanyManager && upg.ParentUserPermissionGroupId == null && cupg.Count() >= 1) { ctvm.IsCurrentUserAssignedGroup = true; }
                    else { ctvm.IsCurrentUserAssignedGroup = upg.PermissionIsActive; }
                }
                else
                {
                    if (_userPermissionGroupRepository.FindByUserId(CurrentUser.Get().Id).Where(x => !x.IsDeleted && x.IsOriginal == true).ToList().Count() == 0) return null;
                    upg = _userPermissionGroupRepository.FindByUserId(CurrentUser.Get().Id).Where(x => !x.IsDeleted && x.IsOriginal == true && x.PermissionIsActive == true).FirstOrDefault();
                    id = upg.Id;
                    ctvm.IsGroupExist = false;
                    ctvm.IsCurrentUserAssignedGroup = false;
                }

                ctvm.IsOriginal = upg.IsOriginal;
                List<int> companyBuildingObjectsIds = (from cbo in upg.UserPermissionGroupTimeZones.Where(x => !x.IsDeleted && (activeUpg == null || activeUpgBuildingIds.Contains(x.BuildingObjectId) || x.Active)) select cbo.BuildingObjectId).ToList();
                if (activeUpgBuildingIds != null)
                {
                    foreach (var actUpgBuildingId in
                        activeUpgBuildingIds.Where(actUpgBuildingId => !companyBuildingObjectsIds.Contains(actUpgBuildingId)))
                    {
                        companyBuildingObjectsIds.Add(actUpgBuildingId);
                    }
                }

                var companyBuildingObjects = _buildingObjectRepository.FindAll(x => !x.IsDeleted && /*role_buildingIds.Contains(x.BuildingId)
                    && */companyBuildingObjectsIds.Contains(x.Id));

                // role_buildingIds.Contains(x.BuildingId) not in need
                List<int> floorsId = (from cbo in companyBuildingObjects.Where(x => x.ParentObjectId.HasValue) select cbo.ParentObjectId.Value).ToList();
                var companyFloorObjects = _buildingObjectRepository.FindAll(x => !x.IsDeleted && floorsId.Contains(x.Id));
                ctvm.Buildings =
                    (from b in
                         (from cbo in companyBuildingObjects select cbo.Building)
                     where !b.IsDeleted
                     select
                         new Node
                         {
                             ParentId = b.LocationId,
                             MyId = b.Id,
                             Name = b.Name
                         }).Distinct(new NodeEqualityComparer()).ToList();

                ctvm.Towns =
                    (from t in
                         (from cbo in companyBuildingObjects select cbo.Building.Location)
                     where !t.IsDeleted
                     select
                         new Node
                         {
                             ParentId = t.CountryId,
                             MyId = t.Id,
                             Name = t.Name
                         }).Distinct(new NodeEqualityComparer()).ToList();

                ctvm.Countries =
                    (from c in
                         (from cbo in companyBuildingObjects select cbo.Building.Location.Country).OrderBy(cc => cc.Name)
                     where !c.IsDeleted
                     select
                         new Node
                         {
                             ParentId = 0,
                             MyId = c.Id,
                             Name = c.Name
                         }).Distinct(new NodeEqualityComparer()).ToList();

                ctvm.Floors =
                    (from f in companyFloorObjects
                     where f.TypeId == (int)BuildingObjectTypes.Floor
                     select
                         new Node
                         {
                             ParentId = f.BuildingId,
                             MyId = f.Id,
                             Name = f.Description,
                             Comment = f.Comment
                         }).Distinct(new NodeEqualityComparer()).ToList();

                ctvm.Objects =
                    (from o in companyBuildingObjects
                     where o.ParentObjectId.HasValue && (o.TypeId == (int)BuildingObjectTypes.Door || o.TypeId == (int)BuildingObjectTypes.Lift || o.TypeId == (int)BuildingObjectTypes.Room)
                     orderby o.TypeId descending
                     select
                         new Node
                         {
                             ParentId = o.ParentObjectId.Value,
                             MyId = o.Id,
                             Name = o.ObjectNr.HasValue ? "#" + o.ObjectNr + " " + o.Description : o.Description,
                             Comment = o.Comment,
                             IsDefaultTimeZone = _userPermissionGroupService.IsDefaultUserTimeZone(o.Id, id.Value),
                             IsRoom = o.TypeId == (int)BuildingObjectTypes.Room ? 1 : 0,
                             StatusIcon = o.StatusIconId.HasValue ? String.Format("../../img/status/{0}.ico", o.StatusIconId) : String.Empty
                         }).Distinct(new NodeEqualityComparer()).ToList();

                ctvm.ActiveObjectIds = _userPermissionGroupService.GetUserBuildingObjectIds(id.Value);
                foreach (var obn in ctvm.Objects)
                {
                    if (obn.IsRoom == 1)
                    {
                        //1 illi 08.05.2018 UserPermissionGroupTimeZone upgtz = _userPermissionGroupTimeZoneRepository.FindAll(x => !x.IsDeleted && x.BuildingObjectId == obn.MyId && x.UserPermissionGroupId == id).FirstOrDefault();
                        int idd = id.GetValueOrDefault();
                        UserPermissionGroupTimeZone upgtz = _userPermissionGroupTimeZoneRepository.FindByPGId(idd).Where(x => !x.IsDeleted && x.BuildingObjectId == obn.MyId && x.UserPermissionGroupId == id).FirstOrDefault();

                        obn.IsArming = upgtz == null ? true : upgtz.IsArming;
                        obn.IsDefaultArming = upgtz == null ? true : upgtz.IsDefaultArming;
                        obn.IsDisarming = upgtz == null ? true : upgtz.IsDisarming;
                        obn.IsDefaultDisarming = upgtz == null ? true : upgtz.IsDefaultDisarming;
                    }
                }
                ctvm.Towns = ctvm.Towns.Where(town => ctvm.Buildings.Any(b => b.ParentId == town.MyId));
                ctvm.Countries = ctvm.Countries.Where(country => ctvm.Towns.Any(town => town.ParentId == country.MyId));
            }
            else
            if (!(CurrentUser.Get().IsCompanyManager || CurrentUser.Get().IsCommonUser))
            {
                IEnumerable<Building> userBuildings;
                if (CurrentUser.Get().IsSuperAdmin)
                {
                    userBuildings = _buildingRepository.FindAll(x => !x.IsDeleted).ToList();
                }
                else
                if (CurrentUser.Get().IsBuildingAdmin)
                {
                    userBuildings = _buildingRepository.FindAll(x => role_buildingIds.Contains(x.Id));
                }
                else return null;
                ctvm.Buildings =
                    (from b in userBuildings
                     select
                         new Node
                         {
                             ParentId = b.LocationId,
                             MyId = b.Id,
                             Name = b.Name
                         }).Distinct(new NodeEqualityComparer()).ToList();

                ctvm.Towns =
                    (from t in (from ub in userBuildings select ub.Location)
                     where !t.IsDeleted
                     select
                         new Node
                         {
                             ParentId = t.CountryId,
                             MyId = t.Id,
                             Name = t.Name
                         }).Distinct(new NodeEqualityComparer()).ToList();

                ctvm.Countries =
                    (from c in (from cbo in userBuildings select cbo.Location.Country).OrderBy(cc => cc.Name)
                     where !c.IsDeleted
                     select
                         new Node
                         {
                             ParentId = 0,
                             MyId = c.Id,
                             Name = c.Name
                         }).Distinct(new NodeEqualityComparer()).ToList();

                List<int> userBuildingIds = (from ub in userBuildings select ub.Id).ToList();
                var userBuildingObjects = _buildingObjectRepository.FindAll(x => !x.IsDeleted && userBuildingIds.Contains(x.BuildingId)).ToList();

                ctvm.Floors =
                    (from f in userBuildingObjects
                     where f.TypeId == (int)BuildingObjectTypes.Floor
                     select
                         new Node
                         {
                             ParentId = f.BuildingId,
                             MyId = f.Id,
                             Name = f.Description,
                             Comment = f.Comment
                         }).Distinct(new NodeEqualityComparer()).ToList();

                ctvm.Objects =
                    (from o in userBuildingObjects
                     where o.ParentObjectId.HasValue && (o.TypeId == (int)BuildingObjectTypes.Door || o.TypeId == (int)BuildingObjectTypes.Lift || o.TypeId == (int)BuildingObjectTypes.Room)
                     orderby o.TypeId descending
                     select
                         new Node
                         {
                             ParentId = o.ParentObjectId.Value,
                             MyId = o.Id,
                             Name = o.ObjectNr.HasValue ? "#" + o.ObjectNr + " " + o.Description : o.Description,
                             Comment = o.Comment,
                             IsDefaultTimeZone = id.HasValue ? _userPermissionGroupService.IsDefaultUserTimeZone(o.Id, id.Value) : true,
                             IsRoom = o.TypeId == (int)BuildingObjectTypes.Room ? 1 : 0,
                             StatusIcon = o.StatusIconId.HasValue ? String.Format("../../img/status/{0}.ico", o.StatusIconId) : String.Empty
                         }).Distinct(new NodeEqualityComparer()).ToList();

                if (id.HasValue)
                {

                    ctvm.ActiveObjectIds = _userPermissionGroupService.GetUserBuildingObjectIds(id.Value);
                    foreach (var obn in ctvm.Objects)
                    {
                        if (obn.IsRoom == 1)
                        {
                            int idd = id.GetValueOrDefault();
                            UserPermissionGroupTimeZone pgtz = _userPermissionGroupTimeZoneRepository.FindByPGId(idd).Where(x => !x.IsDeleted && x.BuildingObjectId == obn.MyId && x.UserPermissionGroupId == id).FirstOrDefault();
                            obn.IsDisarming = pgtz == null ? true : pgtz.IsDisarming;
                            obn.IsDefaultDisarming = pgtz == null ? true : pgtz.IsDefaultDisarming;
                            obn.IsArming = pgtz == null ? true : pgtz.IsArming;
                            obn.IsDefaultArming = pgtz == null ? true : pgtz.IsDefaultArming;
                        }
                    }
                }
                else
                {
                    foreach (var obn in ctvm.Objects)
                    {
                        if (obn.IsRoom == 1)
                        {
                            obn.IsArming = obn.IsDisarming = obn.IsDefaultArming = obn.IsDefaultDisarming = true;
                        }
                    }
                }
                ctvm.Towns = ctvm.Towns.Where(town => ctvm.Buildings.Any(b => b.ParentId == town.MyId));
                ctvm.Countries = ctvm.Countries.Where(country => ctvm.Towns.Any(town => town.ParentId == country.MyId));
            }
            return PartialView("Tree", ctvm);
        }
Ejemplo n.º 6
0
        public List <SelectListItem> GetBuildings(int userId)
        {
            var result = new List <SelectListItem>();
            var user   = new UserItem();

            Mapper.Map(_userRepository.FindById(userId), user);
            var role_building_ids = GetRoleBuildings(_buildingRepository, _roleRepository);

            /*if( !user.IsSuperAdmin)
             *          {
             *                  var user_role = user.UserRoles.Where(x => !x.IsDeleted && x.ValidFrom < DateTime.Now && x.ValidTo.AddDays(1) > DateTime.Now).FirstOrDefault();
             *                  if( user_role == null )
             *                  {
             *                          return result;
             *                  }
             *                  var user_role_building_ids = from b in user_role.Role.RoleBuildings.Where(rb => !rb.IsDeleted) select b.BuildingId;
             *
             *                  role_building_ids = role_building_ids.Where(x => user_role_building_ids.Contains(x)).ToList();
             *          }
             *
             */
            if (!user.CompanyId.HasValue && !user.IsBuildingAdmin && !user.IsSuperAdmin)
            {
                return(result);
            }
            if (user.CompanyId.HasValue)
            {
                var company = _companyRepository.FindById(user.CompanyId.Value);
                if (company.ParentId != null)
                {
                    company = _companyRepository.FindById(company.ParentId.Value);
                }

                List <int> companyBuildingObjectsIds =
                    (from cbo in company.CompanyBuildingObjects.Where(x => !x.IsDeleted) select cbo.BuildingObjectId).ToList();

                var companyBuildingObjects =
                    _buildingObjectRepository.FindAll(x => !x.IsDeleted && x.TypeId == 1 && companyBuildingObjectsIds.Contains(x.Id) && role_building_ids.Contains(x.BuildingId));

                foreach (var cbo in companyBuildingObjects.Where(cbo => !result.Any(rr => rr.Value == cbo.BuildingId.ToString())))
                {
                    result.Add(new SelectListItem()
                    {
                        Value = cbo.BuildingId.ToString(), Text = cbo.Building.Name
                    });
                }
            }
            else
            {
                if (CurrentUser.Get().IsSuperAdmin&& (user.IsBuildingAdmin || user.IsSuperAdmin))
                {
                    var buildingObjects =
                        _buildingObjectRepository.FindAll(x => !x.IsDeleted && x.TypeId == 1 && role_building_ids.Contains(x.BuildingId));

                    foreach (var cbo in buildingObjects.Where(cbo => !result.Any(rr => rr.Value == cbo.BuildingId.ToString())))
                    {
                        result.Add(new SelectListItem()
                        {
                            Value = cbo.BuildingId.ToString(), Text = cbo.Building.Name
                        });
                    }
                }
                else
                {
                    if (CurrentUser.Get().IsBuildingAdmin&& user.IsBuildingAdmin)
                    {
                        var userBuildingObjectIds = (from ubo in _userBuildingRepository.FindByUserId(CurrentUser.Get().Id) select ubo.BuildingId).ToList();

                        var buildingObjects =
                            _buildingObjectRepository.FindAll(x => !x.IsDeleted && x.TypeId == 1 && role_building_ids.Contains(x.BuildingId) && userBuildingObjectIds.Contains(x.BuildingId));

                        foreach (var cbo in buildingObjects.Where(cbo => !result.Any(rr => rr.Value == cbo.BuildingId.ToString())))
                        {
                            result.Add(new SelectListItem()
                            {
                                Value = cbo.BuildingId.ToString(), Text = cbo.Building.Name
                            });
                        }
                    }
                }
            }
            return(result);
        }