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.º 2
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 IEnumerable <PublicAccessEntry> PerformGetByQuery(IQuery <PublicAccessEntry> query)
        {
            var sqlClause  = GetBaseQuery(false);
            var translator = new SqlTranslator <PublicAccessEntry>(sqlClause, query);
            var sql        = translator.Translate();

            var factory = new PublicAccessEntryFactory();
            var dtos    = Database.Fetch <AccessDto, AccessRuleDto, AccessDto>(new AccessRulesRelator().Map, sql);

            return(dtos.Select(factory.BuildEntity));
        }
Ejemplo n.º 4
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();
    }
        protected override IEnumerable <PublicAccessEntry> PerformGetAll(params Guid[] ids)
        {
            var sql = GetBaseQuery(false);

            if (ids.Any())
            {
                sql.Where("umbracoAccess.id IN (@ids)", new { ids = ids });
            }

            var factory = new PublicAccessEntryFactory();
            var dtos    = Database.Fetch <AccessDto, AccessRuleDto, AccessDto>(new AccessRulesRelator().Map, sql);

            return(dtos.Select(factory.BuildEntity));
        }
Ejemplo n.º 6
0
        protected override IEnumerable <PublicAccessEntry> PerformGetByQuery(IQuery <PublicAccessEntry> query)
        {
            var sqlClause  = GetBaseQuery(false);
            var translator = new SqlTranslator <PublicAccessEntry>(sqlClause, query);
            var sql        = translator.Translate();

            var factory = new PublicAccessEntryFactory();

            //MUST be ordered by this GUID ID for the AccessRulesRelator to work
            sql.OrderBy <AccessDto>(dto => dto.Id, SqlSyntax);

            var dtos = Database.Fetch <AccessDto, AccessRuleDto, AccessDto>(new AccessRulesRelator().Map, sql);

            return(dtos.Select(factory.BuildEntity));
        }
Ejemplo n.º 7
0
        protected override IEnumerable <PublicAccessEntry> PerformGetAll(params Guid[] ids)
        {
            var sql = GetBaseQuery(false);

            if (ids.Any())
            {
                sql.Where("umbracoAccess.id IN (@ids)", new { ids = ids });
            }

            var factory = new PublicAccessEntryFactory();

            //MUST be ordered by this GUID ID for the AccessRulesRelator to work
            sql.OrderBy <AccessDto>(dto => dto.Id, SqlSyntax);

            var dtos = Database.Fetch <AccessDto, AccessRuleDto, AccessDto>(new AccessRulesRelator().Map, sql);

            return(dtos.Select(factory.BuildEntity));
        }
        protected override PublicAccessEntry PerformGet(Guid id)
        {
            var sql = GetBaseQuery(false);

            sql.Where(GetBaseWhereClause(), new { Id = id });

            var taskDto = Database.Fetch <AccessDto, AccessRuleDto, AccessDto>(new AccessRulesRelator().Map, sql).FirstOrDefault();

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

            var factory = new PublicAccessEntryFactory();
            var entity  = factory.BuildEntity(taskDto);

            return(entity);
        }