예제 #1
0
        public static IQueryable <TTarget> Build <TSource, TTarget>(IQueryable <TSource> source, ModelConvertOptions options)
        {
            if (options == null)
            {
                options = ModelConvert.Target <TTarget>().Source <TSource>().Options.IgnoreReadOnly();
            }

            options.IgnoreReadOnly();

            MemberBindingState state = new MemberBindingState(Expression.Parameter(typeof(TSource), "obj"));

            ModelConvert.WalkConvertiblProperties(null, ModelInfo.GetModelInfo(typeof(TTarget)), null, ModelInfo.GetModelInfo(typeof(TSource)), options, BuildProperty, state);

            var body = Expression.MemberInit(Expression.New(typeof(TTarget)), state.Bindings);

            var lambda = Expression.Lambda <Func <TSource, TTarget> >(body, state.Parameter);

            return(source.Select(lambda));
        }
예제 #2
0
        protected virtual async Task UpdateUserAsync(TUser entity, TUserModel model, EntityAction action)
        {
            ModelConvert.Target(entity)
            .Ignore(o => o.PasswordHash)
            .Ignore(o => o.Roles)
            .Ignore(o => o.Id)
            .PopulateBy(model);

            if (model.Roles != null)
            {
                entity.Roles.Clear();

                var rm = RoleManager;

                foreach (var name in model.Roles)
                {
                    var role = await rm.FindByNameAsync(name);

                    entity.Roles.Add(new IdentityUserRole <TKey> {
                        RoleId = role.Id
                    });
                }
            }
        }