Exemplo n.º 1
0
        //Upsert(Add and Update) SecurityGroup to the SystemUserSecurity table...
        public void AddAllSystemUserSecurities(string systemUserID, string companyID)
        {   //remove them all then we will add them all...
            RemoveAllSystemUserSecurities(systemUserID, companyID);
            //declare a different context as to not disturb the repostitory context that is tracking SystemUsers
            SystemUserEntities context = new SystemUserEntities(_rootUri);

            //get Security Groups...
            context.MergeOption = MergeOption.AppendOnly;
            context.IgnoreResourceNotFoundException = true;
            var queryResult = from q in context.SecurityGroups
                              where q.CompanyID == companyID
                              select q;

            foreach (SecurityGroup item in queryResult.ToList())
            {
                SystemUserSecurity systemUserSecurity = new SystemUserSecurity();
                systemUserSecurity.CompanyID       = companyID;
                systemUserSecurity.SystemUserID    = systemUserID;
                systemUserSecurity.SecurityGroupID = item.SecurityGroupID;
                context.MergeOption = MergeOption.NoTracking;
                context.AddToSystemUserSecurities(systemUserSecurity);
                context.SaveChanges();
            }
            context = null;
        }
Exemplo n.º 2
0
        //Upsert(Add and Update) SecurityGroup to the UserSecurity table...
        public void AddSystemUserSecurity(string systemUserID, string securityGroupID, string companyID)
        {//declare a different context as to not disturb the repostitory context that is tracking SystemUsers
            SystemUserEntities context = new SystemUserEntities(_rootUri);

            //make sure it does not exist all ready...
            context.MergeOption = MergeOption.AppendOnly;
            context.IgnoreResourceNotFoundException = true;
            var queryResult = from q in context.SystemUserSecurities
                              where q.CompanyID == companyID &&
                              q.SystemUserID == systemUserID &&
                              q.SecurityGroupID == securityGroupID
                              select q;

            if (queryResult.ToList().Count() == 0)
            {//it does not exist add it...
                SystemUserSecurity systemUserSecurity = new SystemUserSecurity();
                systemUserSecurity.CompanyID       = companyID;
                systemUserSecurity.SystemUserID    = systemUserID;
                systemUserSecurity.SecurityGroupID = securityGroupID;
                context.MergeOption = MergeOption.NoTracking;
                context.AddToSystemUserSecurities(systemUserSecurity);
                context.SaveChanges();
            }
            context = null;
        }
        public void DeleteFromRepository(SystemUserCode itemCode)
        {
            if (_repositoryContext.GetEntityDescriptor(itemCode) != null)
            {//if it exists in the db delete it from the db
                SystemUserEntities context = new SystemUserEntities(_rootUri);
                context.MergeOption = MergeOption.AppendOnly;
                context.IgnoreResourceNotFoundException = true;
                SystemUserCode deletedSystemUserCode = (from q in context.SystemUserCodes
                                                        where q.SystemUserCodeID == itemCode.SystemUserCodeID
                                                        select q).FirstOrDefault();
                if (deletedSystemUserCode != null)
                {
                    context.DeleteObject(deletedSystemUserCode);
                    context.SaveChanges();
                }
                context = null;

                _repositoryContext.MergeOption = MergeOption.AppendOnly;
                //if it is being tracked remove it...
                if (GetSystemUserCodeEntityState(itemCode) != EntityStates.Detached)
                {
                    _repositoryContext.Detach(itemCode);
                }
            }
        }
Exemplo n.º 4
0
        //delete SecurityGroup from the SystemUserSecurity table...
        public void RemoveAllSystemUserSecurities(string systemUserID, string companyID)
        {//declare a different context as to not disturb the repostitory context that is tracking SystemUsers
            SystemUserEntities context = new SystemUserEntities(_rootUri);

            context.MergeOption = MergeOption.AppendOnly;
            context.IgnoreResourceNotFoundException = true;
            var deleteItems = from q in context.SystemUserSecurities
                              where q.CompanyID == companyID &&
                              q.SystemUserID == systemUserID
                              select q;

            foreach (SystemUserSecurity item in deleteItems.ToList())
            {
                context.DeleteObject(item);
                context.SaveChanges();
            }
            context = null;
        }
Exemplo n.º 5
0
        //delete SecurityGroup from the SystemUserSecurity table...
        public void RemoveSystemUserSecurity(string systemUserID, string securityGroupID, string companyID)
        {//declare a different context as to not disturb the repostitory context that is tracking SystemUsers
            SystemUserEntities context = new SystemUserEntities(_rootUri);

            context.MergeOption = MergeOption.AppendOnly;
            context.IgnoreResourceNotFoundException = true;
            var deleteItem = (from q in context.SystemUserSecurities
                              where q.CompanyID == companyID &&
                              q.SystemUserID == systemUserID &&
                              q.SecurityGroupID == securityGroupID
                              select q).FirstOrDefault();

            if (deleteItem != null)
            {
                context.DeleteObject(deleteItem);
                context.SaveChanges();
            }
            context = null;
        }
 public void CommitRepository()
 {
     _repositoryContext.MergeOption = MergeOption.AppendOnly;
     _repositoryContext.SaveChanges();
 }