Esempio n. 1
0
        public JsonNetResult QueryMyMerchant(WebQueryFilter filter)
        {
            if (this.Auth.GetAuthenticatedUser() == null)
            {
                return new JsonNetResult()
                       {
                           Data = new { }
                       }
            }
            ;

            filter.Columns.Add(new QueryColumnFilter()
            {
                Data       = "EnjoyUser.Id",
                Searchable = true,
                DbType     = System.Data.DbType.Int64,
                Search     = new SearchColumnFilter()
                {
                    Regex = false, Value = this.Auth.GetAuthenticatedUser().Id
                }
            });

            var condition = new PagingCondition(filter.Start, filter.Length);
            var viewModel = this.Merchant.QueryMerchants(filter, condition);

            return(new JsonNetResult()
            {
                Data = viewModel
            });
        }
Esempio n. 2
0
        public static ICriteria WithQueryOrder(this ICriteria criteria, WebQueryFilter filter)
        {
            if (criteria == null)
            {
                throw new ArgumentNullException("criteria");
            }
            if (filter == null)
            {
                throw new ArgumentNullException("filter");
            }
            if (filter.Columns == null)
            {
                throw new ArgumentNullException("filter.Columns");
            }

            foreach (var order in filter.Order.Select((ctx) =>
            {
                if (string.IsNullOrEmpty(ctx.ColumnName))
                {
                    return(new Order(filter.Columns[ctx.Column].Data, ctx.Dir == Direction.Asc));
                }
                else
                {
                    return(new Order(ctx.ColumnName, ctx.Dir == Direction.Asc));
                }
            }))
            {
                criteria.AddOrder(order);
            }
            return(criteria);
        }
Esempio n. 3
0
        public JsonNetResult QueryCouponCard(WebQueryFilter filter)
        {
            if (this.Auth.GetAuthenticatedUser() == null)
            {
                return new JsonNetResult()
                       {
                           Data = new { }
                       }
            }
            ;

            var merchant = this.Merchant.GetDefaultMerchant();

            filter.Columns.Add(new QueryColumnFilter()
            {
                Data       = "Merchant.Id",
                Searchable = true,
                DbType     = System.Data.DbType.Int64,
                Search     = new SearchColumnFilter()
                {
                    Regex = false, Value = merchant.Id
                }
            });
            var model     = this.CardCoupon.QueryCardCoupon(filter, new PagingCondition(filter.Start, filter.Length));
            var viewModel = new PagingData <CardCouponWithoutWapperViewModel>(model.Items.Select(o => new CardCouponWithoutWapperViewModel(o)))
            {
                Paging     = model.Paging,
                TotalCount = model.TotalCount
            };

            return(new JsonNetResult()
            {
                Data = viewModel
            });
        }
Esempio n. 4
0
        public PagingData <M> Query(
            WebQueryFilter filter,
            PagingCondition condition,
            Action <ICriteria> builder,
            Func <R, M> convert)
        {
            var session  = this.OS.TransactionManager.GetSession();
            var criteria = session.CreateCriteria(typeof(R));

            condition = condition ?? new PagingCondition(0, int.MaxValue);
            if (builder != null)
            {
                builder(criteria);
            }
            if (filter != null)
            {
                criteria.WithQueryFilter(filter).WithQueryOrder(filter);
            }
            criteria.ClearOrders();
            var pageCriteria = CriteriaTransformer.Clone(criteria);
            var page         = (condition.Skip / condition.Take) - 1;

            return(new PagingData <M>()
            {
                TotalCount = Convert.ToInt32(criteria.SetProjection(Projections.RowCount()).UniqueResult()),
                Items = pageCriteria.SetFirstResult(condition.Skip)
                        .SetMaxResults(condition.Take)
                        .List <R>()
                        .Select(o => convert(o))
                        .ToList(),
                Paging = new Paging(page, condition.Take)
            });
        }
Esempio n. 5
0
 public PagingData <MerchantModel> QueryMerchants(
     WebQueryFilter filter,
     PagingCondition condition)
 {
     return(this.Query(condition, (builder) =>
     {
         builder.WithQueryFilter(filter);
         //builder.WithQueryOrder(filter);
     },
                       (record) => Convert(record)));
 }
Esempio n. 6
0
        public BaseResponse Delete(WebQueryFilter filter)
        {
            var session  = this.OS.TransactionManager.GetSession();
            var criteria = session.CreateCriteria(typeof(R));

            criteria.WithQueryFilter(filter);
            foreach (var item in criteria.SetMaxResults(int.MaxValue).List <R>())
            {
                session.Delete(item);
            }
            return(new BaseResponse(Constants.Success));
        }
Esempio n. 7
0
        public JsonNetResult QueryMyShops(WebQueryFilter filter)
        {
            if (this.Auth.GetAuthenticatedUser() == null)
            {
                return new JsonNetResult()
                       {
                           Data = new { }
                       }
            }
            ;
            var merchant = this.Merchant.GetDefaultMerchant();

            if (filter.Fixation != null)
            {
                foreach (var key in filter.Fixation.Keys)
                {
                    var column = new QueryColumnFilter()
                    {
                        Data       = key,
                        Searchable = true,
                        Search     = new SearchColumnFilter()
                        {
                            Regex = false, Value = filter.Fixation[key]
                        }
                    };
                    if (key.Equals("Merchant.Id", StringComparison.OrdinalIgnoreCase))
                    {
                        column.DbType = System.Data.DbType.Int64;
                    }
                    filter.Columns.Add(column);
                }
            }

            var condition = new PagingCondition(filter.Start, filter.Length);
            var model     = client.Convert(this.Shop.QueryShops(filter, condition));

            model.Draw = filter.Draw;
            return(new JsonNetResult()
            {
                Data = model
            });
        }
Esempio n. 8
0
 public PagingData <ShopModel> QueryShops(WebQueryFilter filter, PagingCondition condition)
 {
     return(Query(filter, condition, null, r => new ShopModel(r)));
 }
Esempio n. 9
0
 public PagingData <CardCounponModel> QueryCardCoupon(WebQueryFilter filter, PagingCondition condition)
 {
     return(base.Query(filter, condition, null, record => new CardCounponModel(record)));
 }
Esempio n. 10
0
        public static ICriteria WithQueryFilter(this ICriteria criteria, WebQueryFilter filter)
        {
            if (criteria == null)
            {
                throw new ArgumentNullException("criteria");
            }
            if (filter == null)
            {
                throw new ArgumentNullException("filter");
            }
            if (filter.Columns == null)
            {
                throw new ArgumentNullException("filter.Columns");
            }

            foreach (var column in filter.Columns)
            {
                var type = column.DbType == null
                    ? column.Search.Value.PredictDbTypeBySearchColumeValue()
                    :column.DbType;

                if (column.Searchable == false || type == null)
                {
                    continue;
                }
                var values = ((column.Search.Value as string[]) ?? new string[] { column.Search.Value.ToString() })
                             .Where(o => string.IsNullOrEmpty(o) == false).ToArray();
                switch (type)
                {
                case System.Data.DbType.DateTime:
                    for (int i = 0; i < values.Length; i++)
                    {
                        switch (i)
                        {
                        case 0:
                            //>=
                            criteria.Add(Restrictions.Ge(column.Data, DateTime.Parse(values[i]).ToUnixStampDateTime()));
                            break;

                        case 1:
                            //<
                            criteria.Add(Restrictions.Lt(column.Data, DateTime.Parse(values[i]).ToUnixStampDateTime()));
                            break;

                        default:
                            break;
                        }
                    }
                    break;

                case System.Data.DbType.Int32:
                    criteria.Add(Restrictions.Eq(column.Data, Int32.Parse(values[0])));
                    break;

                case System.Data.DbType.Int64:
                    criteria.Add(Restrictions.Eq(column.Data, Int64.Parse(values[0])));
                    break;

                case System.Data.DbType.Decimal:
                    criteria.Add(Restrictions.Eq(column.Data, decimal.Parse(values[0])));
                    break;

                //case System.Data.DbType.String:
                //    criteria.Add(Restrictions.Eq(column.Data, values[0]));
                //    break;
                default:
                    criteria.Add(Restrictions.Eq(column.Data, column.Search.Value));
                    break;
                }
            }
            return(criteria);
        }