Ejemplo n.º 1
0
        protected override void PersistNewItem(PublicAccessEntry entity)
        {
            entity.AddingEntity();
            entity.Rules.ForEach(x => x.AddingEntity());

            var factory = new PublicAccessEntryFactory();
            var dto     = factory.BuildDto(entity);

            Database.Insert(dto);
            //update the id so HasEntity is correct
            entity.Id = entity.Key.GetHashCode();

            foreach (var rule in dto.Rules)
            {
                rule.AccessId = entity.Key;
                Database.Insert(rule);
                //update the id so HasEntity is correct
                var entityRule = entity.Rules.First(x => x.Key == rule.Id);
                entityRule.Id = entityRule.Key.GetHashCode();
                //double make sure that this is set since it is possible to add rules via ctor without AddRule
                entityRule.AccessEntryId = entity.Key;
            }

            entity.ResetDirtyProperties();
        }
        protected override void PersistNewItem(PublicAccessEntry entity)
        {
            entity.AddingEntity();
            foreach (var rule in entity.Rules)
            {
                rule.AddingEntity();
            }

            var dto = PublicAccessEntryFactory.BuildDto(entity);

            Database.Insert(dto);
            //update the id so HasEntity is correct
            entity.Id = entity.Key.GetHashCode();

            foreach (var rule in dto.Rules)
            {
                rule.AccessId = entity.Key;
                Database.Insert(rule);
            }

            //update the id so HasEntity is correct
            foreach (var rule in entity.Rules)
            {
                rule.Id = rule.Key.GetHashCode();
            }

            entity.ResetDirtyProperties();
        }
Ejemplo n.º 3
0
    protected override void PersistUpdatedItem(PublicAccessEntry entity)
    {
        entity.UpdatingEntity();
        foreach (PublicAccessRule rule in entity.Rules)
        {
            if (rule.HasIdentity)
            {
                rule.UpdatingEntity();
            }
            else
            {
                rule.AddingEntity();
            }
        }

        AccessDto dto = PublicAccessEntryFactory.BuildDto(entity);

        Database.Update(dto);

        foreach (Guid removedRule in entity.RemovedRules)
        {
            Database.Delete <AccessRuleDto>("WHERE id=@Id", new { Id = removedRule });
        }

        foreach (PublicAccessRule rule in entity.Rules)
        {
            if (rule.HasIdentity)
            {
                var count = Database.Update(dto.Rules.Single(x => x.Id == rule.Key));
                if (count == 0)
                {
                    throw new InvalidOperationException("No rows were updated for the access rule");
                }
            }
            else
            {
                Database.Insert(new AccessRuleDto
                {
                    Id         = rule.Key,
                    AccessId   = dto.Id,
                    RuleValue  = rule.RuleValue,
                    RuleType   = rule.RuleType,
                    CreateDate = rule.CreateDate,
                    UpdateDate = rule.UpdateDate,
                });

                // update the id so HasEntity is correct
                rule.Id = rule.Key.GetHashCode();
            }
        }

        entity.ResetDirtyProperties();
    }