Example #1
0
        public void OnReturn(IRetrieveRequestHandler handler)
        {
            if (ReferenceEquals(null, Target) ||
                !handler.ShouldSelectField(Target))
                return;

            var idField = (handler.Row as IIdRow).IdField;
            var fld = NoteRow.Fields;

            var listRequest = new ListRequest
            {
                ColumnSelection = ColumnSelection.List,
                EqualityFilter = new Dictionary<string, object>
                {
                    { fld.EntityType.PropertyName, handler.Row.Table },
                    { fld.EntityId.PropertyName, idField[handler.Row] ?? -1 }
                }
            };

            var notes = new NoteRepository().List(handler.Connection, listRequest).Entities;

            // users might be in another database, in another db server, so we can't simply use a join here
            var userIdList = notes.Where(x => x.InsertUserId != null).Select(x => x.InsertUserId.Value).Distinct();
            if (userIdList.Any())
            {
                var u = UserRow.Fields;
                IDictionary<int, string> userDisplayNames;
                using (var connection = SqlConnections.NewFor<UserRow>())
                    userDisplayNames = connection.Query(new SqlQuery()
                            .From(u)
                            .Select(u.UserId)
                            .Select(u.DisplayName)
                            .Where(u.UserId.In(userIdList)))
                        .ToDictionary(x => (int)x.UserId, x => (string)x.DisplayName);

                string s;
                foreach (var x in notes)
                    if (x.InsertUserId != null && userDisplayNames.TryGetValue(x.InsertUserId.Value, out s))
                        x.InsertUserDisplayName = s;
            }

            Target.AsObject(handler.Row, notes);
        }
Example #2
0
 public void OnValidateRequest(IRetrieveRequestHandler handler) { }
Example #3
0
 public void OnBeforeExecuteQuery(IRetrieveRequestHandler handler) { }
Example #4
0
 public void OnPrepareQuery(IRetrieveRequestHandler handler, SqlQuery query) { }
 public void OnReturn(IRetrieveRequestHandler handler) { }
Example #6
0
 public void OnAfterExecuteQuery(IRetrieveRequestHandler handler) { }
 public void OnPrepareQuery(IRetrieveRequestHandler handler, SqlQuery query)
 {
     var user = (UserDefinition)Authorization.UserDefinition;
     if (!Authorization.HasPermission(PermissionKeys.Tenants))
         query.Where(fldTenantId == user.TenantId);
 }
        public void OnReturn(IRetrieveRequestHandler handler)
        {
            if (ReferenceEquals(null, Target) ||
                !handler.AllowSelectField(Target) ||
                !handler.ShouldSelectField(Target))
                return;

            var idField = (Field)((handler.Row as IIdRow).IdField);

            var listHandler = listHandlerFactory();

            var listRequest = new ListRequest
            {
                ColumnSelection = ColumnSelection.KeyOnly,
                IncludeColumns = new HashSet<string>
                {
                    itemKeyField.PropertyName ?? itemKeyField.Name
                },
                Criteria = thisKeyCriteria == new ValueCriteria(idField.AsObject(handler.Row)) & filterCriteria
            };

            IListResponse response = listHandler.Process(handler.Connection, listRequest);

            var list = listFactory();
            foreach (Row item in response.Entities)
                list.Add(itemKeyField.AsObject(item));

            Target.AsObject(handler.Row, list);
        }
        public void OnReturn(IRetrieveRequestHandler handler)
        {
            if (ReferenceEquals(null, Target) ||
                !handler.AllowSelectField(Target) ||
                !handler.ShouldSelectField(Target))
                return;

            var idField = (Field)((handler.Row as IIdRow).IdField);

            var listHandler = listHandlerFactory();

            var listRequest = new ListRequest
            {
                ColumnSelection = this.attr.ColumnSelection,
                IncludeColumns = this.includeColumns,
                Criteria = foreignKeyCriteria == new ValueCriteria(idField.AsObject(handler.Row)) & filterCriteria
            };

            IListResponse response = listHandler.Process(handler.Connection, listRequest);

            var list = rowListFactory();
            foreach (var item in response.Entities)
                list.Add(item);

            Target.AsObject(handler.Row, list);
        }
 public virtual void OnApplyFilters(IRetrieveRequestHandler handler, SqlQuery query)
 {
 }
        public void OnReturn(IRetrieveRequestHandler handler)
        {
            if (ReferenceEquals(null, Target) ||
                !handler.ShouldSelectField(Target))
                return;

            var idField = (handler.Row as IIdRow).IdField;

            var listHandler = listHandlerFactory();

            var listRequest = new ListRequest
            {
                ColumnSelection = ColumnSelection.List,
                EqualityFilter = new Dictionary<string, object>
                {
                    { foreignKeyField.PropertyName ?? foreignKeyField.Name, idField[handler.Row] }
                }
            };

            IListResponse response = listHandler.Process(handler.Connection, listRequest);

            var list = rowListFactory();
            foreach (var item in response.Entities)
                list.Add(item);

            Target.AsObject(handler.Row, list);
        }