/// <summary>
        /// Service method for calling other methods that converts Expression
        /// </summary>
        /// <param name="predicate">Expression to convert</param>
        /// <returns>Converted expression</returns>
        private Expression <Func <TEntity, bool> > ConvertExpression(Expression <Func <TDalEntity, bool> > predicate)
        {
            var param = Expression.Parameter(typeof(TEntity));
            IDictionary <string, string> mapperDictionary;

            PropertyMapperDictionaries.TryGetMapperDictionary(typeof(TDalEntity), out mapperDictionary);
            var result = new ExpressionConverter <TDalEntity, TEntity>(param, mapperDictionary).Visit(predicate.Body);

            return(Expression.Lambda <Func <TEntity, bool> >(result, param));
        }
 /// <summary>
 /// Count of entities matching expression
 /// </summary>
 /// <param name="predicate">Expression</param>
 /// <returns>Count of entities</returns>
 public int Count(Expression <Func <BllBid, bool> > predicate = null)
 {
     if (predicate != null)
     {
         var param = Expression.Parameter(typeof(DalBid));
         IDictionary <string, string> mapperDictionary;
         PropertyMapperDictionaries.TryGetMapperDictionary(typeof(BllBid), out mapperDictionary);
         var result = new ExpressionConverter <BllBid, DalBid>(param, mapperDictionary).Visit(predicate.Body);
         Expression <Func <DalBid, bool> > lambda = Expression.Lambda <Func <DalBid, bool> >(result, param);
         return(context.BidsRepository.Count(lambda));
     }
     return(context.BidsRepository.Count());
 }
예제 #3
0
        /// <summary>
        /// Get range of comments
        /// </summary>
        /// <param name="skip">Number of skiped comments matched the predicate</param>
        /// <param name="take">Number of comments to take</param>
        /// <param name="predicate">Expression to match</param>
        /// <returns>Enumeration with comments matching the predicate</returns>
        public async Task <IEnumerable <BllComment> > GetRange(int skip, int take = 12, Expression <Func <BllComment, bool> > predicate = null)
        {
            Expression <Func <DalCommentary, bool> > lambda = null;

            if (predicate != null)
            {
                var param = Expression.Parameter(typeof(DalCommentary));
                IDictionary <string, string> mapperDictionary;
                PropertyMapperDictionaries.TryGetMapperDictionary(typeof(BllComment), out mapperDictionary);
                var result = new ExpressionConverter <BllComment, DalCommentary>(param, mapperDictionary).Visit(predicate.Body);
                lambda = Expression.Lambda <Func <DalCommentary, bool> >(result, param);
            }
            return((await context.CommentsRepository.GetRange(skip, take, lambda)).Select(t => t.ToBllComment()));
        }
        /// <summary>
        /// Get user matching the predicate
        /// </summary>
        /// <param name="predicate">Expression to match</param>
        /// <returns>BllUser if succeded</returns>
        public async Task <BllUser> GetByPredicate(Expression <Func <BllUser, bool> > predicate)
        {
            var param = Expression.Parameter(typeof(BllUser));
            IDictionary <string, string> mapperDictionary;

            PropertyMapperDictionaries.TryGetMapperDictionary(typeof(BllUser), out mapperDictionary);
            var result = new ExpressionConverter <BllUser, DalUser>(param, mapperDictionary).Visit(predicate.Body);
            Expression <Func <DalUser, bool> > lambda = Expression.Lambda <Func <DalUser, bool> >(result, param);
            DalUser u;

            try
            {
                u = await context.UserStore.GetByPredicate(lambda);
            }
            catch
            {
                throw new InvalidOperationException();
            }

            return(u.ToBllUser());
        }
        /// <summary>
        /// Get lots matching predicate
        /// </summary>
        /// <param name="predicate">Expression to match</param>
        /// <returns></returns>
        public async Task <IEnumerable <BllLot> > GetByPredicate(Expression <Func <BllLot, bool> > predicate)
        {
            var param = Expression.Parameter(typeof(DalLot));
            IDictionary <string, string> mapperDictionary;

            PropertyMapperDictionaries.TryGetMapperDictionary(typeof(BllLot), out mapperDictionary);
            var result = new ExpressionConverter <BllLot, DalLot>(param, mapperDictionary).Visit(predicate.Body);
            Expression <Func <DalLot, bool> > lambda = Expression.Lambda <Func <DalLot, bool> >(result, param);
            IEnumerable <BllLot> l;

            try
            {
                l = (await Context.LotsRepository.GetByPredicate(lambda)).Select(t => t.ToBllLot());
            }
            catch
            {
                throw new InvalidOperationException();
            }

            return(l);
        }
예제 #6
0
        /// <summary>
        /// Gets user by predicate (not recommended to use)
        /// </summary>
        /// <param name="predicate">Condition</param>
        /// <returns>DalUser if succsess</returns>
        public Task <DalUser> GetByPredicate(Expression <Func <DalUser, bool> > predicate)
        {
            var param = Expression.Parameter(typeof(User));
            IDictionary <string, string> mapperDictionary;

            PropertyMapperDictionaries.TryGetMapperDictionary(typeof(DalUser), out mapperDictionary);
            var result = new ExpressionConverter <DalUser, User>(param, mapperDictionary).Visit(predicate.Body);
            Expression <Func <User, bool> > lambda = Expression.Lambda <Func <User, bool> >(result, param);
            User u;

            try
            {
                u = context.Set <User>().FirstOrDefault(lambda);
            }
            catch
            {
                throw new InvalidOperationException();
            }

            return(Task.FromResult <DalUser>(u.ToDalUser()));
        }