Ejemplo n.º 1
0
        public static async Task SaveGroupPolicyAsync(string tenant, int officeId, int roleId, List <AccessPolicyInfo> policies)
        {
            using (var db = DbProvider.Get(FrapidDbServer.GetConnectionString(tenant), tenant).GetDatabase())
            {
                db.BeginTransaction();

                var sql = new Sql();
                sql.Append("DELETE FROM auth.group_entity_access_policy");
                sql.Append("WHERE office_id = @0", officeId);
                sql.Append("AND role_id = @0", roleId);

                await db.ExecuteAsync(sql).ConfigureAwait(false);


                foreach (var policy in policies)
                {
                    var poco = new GroupEntityAccessPolicy
                    {
                        EntityName   = policy.EntityName,
                        OfficeId     = officeId,
                        RoleId       = roleId,
                        AccessTypeId = policy.AccessTypeId,
                        AllowAccess  = policy.AllowAccess
                    };


                    await db.InsertAsync("auth.group_entity_access_policy", "group_entity_access_policy_id", true, poco).ConfigureAwait(false);
                }

                db.CompleteTransaction();
            }
        }
Ejemplo n.º 2
0
        public static async Task SaveGroupPolicyAsync(string tenant, int officeId, int roleId, List<AccessPolicyInfo> policies)
        {
            using (var db = DbProvider.Get(FrapidDbServer.GetConnectionString(tenant), tenant).GetDatabase())
            {
                try
                {
                    await db.BeginTransactionAsync().ConfigureAwait(false);

                    var sql = new Sql();
                    sql.Append("DELETE FROM auth.group_entity_access_policy");
                    sql.Append("WHERE office_id = @0", officeId);
                    sql.Append("AND role_id = @0", roleId);

                    await db.NonQueryAsync(sql).ConfigureAwait(false);


                    foreach (var policy in policies)
                    {
                        var poco = new GroupEntityAccessPolicy
                        {
                            EntityName = policy.EntityName,
                            OfficeId = officeId,
                            RoleId = roleId,
                            AccessTypeId = policy.AccessTypeId,
                            AllowAccess = policy.AllowAccess
                        };


                        await db.InsertAsync("auth.group_entity_access_policy", "group_entity_access_policy_id", true, poco).ConfigureAwait(false);
                    }

                    db.CommitTransaction();
                }
                catch
                {
                    db.RollbackTransaction();
                    throw;
                }
            }
        }