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.º 2
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.º 3
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;
        }