Пример #1
0
        public async Task <SCIMRepresentation> FindSCIMRepresentationByAttribute(string schemaAttributeId, string value, string endpoint = null)
        {
            var record = await IncludeRepresentationNavigationProperties(IncludeRepresentationAttributeNavigationProperties(_scimDbContext.SCIMRepresentationAttributeLst)
                                                                         .Where(a => (endpoint == null || endpoint == a.Representation.ResourceType) && a.SchemaAttributeId == schemaAttributeId && a.Values.Any(v => v.ValueInteger != null && v.ValueString == value))
                                                                         .Select(a => a.Representation))
                         .AsNoTracking()
                         .FirstOrDefaultAsync();

            if (record == null)
            {
                return(null);
            }

            var result = record.ToDomain();

            _scimDbContext.Entry(record).State = EntityState.Detached;
            return(result);
        }
        private void Detach(SCIMRepresentationModel representation)
        {
            _scimDbContext.Entry(representation).State = EntityState.Detached;
            var attributes = _scimDbContext.ChangeTracker.Entries().Where(et =>
            {
                var att = et.Entity as SCIMRepresentationAttributeModel;
                if (att == null)
                {
                    return(false);
                }

                return(att.RepresentationId == representation.Id);
            });
            var ids = attributes.Select(_ => ((SCIMRepresentationAttributeModel)_.Entity).Id).ToList();

            foreach (var attribute in attributes)
            {
                _scimDbContext.Entry(attribute.Entity).State = EntityState.Detached;
            }

            var attributeValues = _scimDbContext.ChangeTracker.Entries().Where(et =>
            {
                var att = et.Entity as SCIMRepresentationAttributeValueModel;
                if (att == null)
                {
                    return(false);
                }

                return(ids.Contains(att.SCIMRepresentationAttributeId));
            });

            foreach (var attribute in attributeValues)
            {
                _scimDbContext.Entry(attribute.Entity).State = EntityState.Detached;
            }
        }
 public bool Update(SCIMRepresentation data)
 {
     _scimDbContext.Entry(data).State = EntityState.Modified;
     return(true);
 }