예제 #1
0
        /// <summary>
        /// Returns items in {value1}-{value2} range with included nagivation properties.
        /// </summary>
        /// <param name="param">Uri parameters</param>
        /// <param name="cancellationToken">Cancellation token if request is cancelled</param>
        /// <returns>List of items in JSON format</returns>
        private async Task <dynamic> GetItemsRangeWithPropsAsync(dynamic param, CancellationToken cancellationToken)
        {
            int         start    = param.value1;
            int         end      = param.value2;
            DbQuery <T> depquery = null;
            var         deps     = context.Set <T>();
            var         props    = ((string)param.props).Split(',');

            for (var i = 0; i < props.Length; i++)
            {
                depquery = i == 0 ? deps.Include(props[i]) : depquery.Include(props[i]);
            }
            if (depquery == null)
            {
                return(Response.AsText("no props specified").WithStatusCode(HttpStatusCode.BadRequest));
            }
            var items = depquery.OrderBy(i => i.Id).Skip(start).Take(end - start);
            await items.LoadAsync(cancellationToken);

            return(Response.AsJson(items));
        }
예제 #2
0
 public async Task BindInstanceAsync(UniContext ctx, CancellationToken token)
 {
     GradeType = await ctx.Set <GradeType>().FindAsync(token, GradeType.Id);
 }