Beispiel #1
0
        // GET: Order
        public ActionResult Index()
        {
            SearchOrderOutput order = OrderLogic.SearchOrder(1);

            return(View("Order", order));
        }
        public SearchOrderOutput Search(SearchOrderInput input)
        {
            using (var dbContext = new AllureContext())
            {
                IQueryable <Order> query = dbContext
                                           .Set <Order>()
                                           .Include(o => o.Details)
                                           .Include(o => o.Customer);

                if (input.Id.HasValue)
                {
                    query = query.Where(o => o.Id == input.Id);
                }

                if (input.Status.HasValue)
                {
                    query = query.Where(o => o.Status == input.Status.Value);
                }

                if (input.MinTotalPrice.HasValue)
                {
                    query = query.Where(o => o.OriginalRealCharge >= input.MinTotalPrice.Value);
                }

                if (input.MaxTotalPrice.HasValue)
                {
                    query = query.Where(o => o.OriginalRealCharge <= input.MaxTotalPrice.Value);
                }

                if (!input.CustomerName.IsNullOrEmpty())
                {
                    query = query.Where(o => o.Customer.FirstName.Contains(input.CustomerName) ||
                                        o.Customer.LastName.Contains(input.CustomerName));
                }

                if (input.MinCreateTime.HasValue)
                {
                    query = query.Where(o => o.CreateTime >= input.MinCreateTime.Value);
                }

                if (input.MaxCreateTime.HasValue)
                {
                    query = query.Where(o => o.CreateTime <= input.MaxCreateTime.Value);
                }

                if (input.MinUpdateTime.HasValue)
                {
                    query = query.Where(o => o.UpdateTime >= input.MinUpdateTime.Value);
                }

                if (input.MaxUpdateTime.HasValue)
                {
                    query = query.Where(o => o.UpdateTime <= input.MaxUpdateTime.Value);
                }

                var result = new SearchOrderOutput();
                result.Count = query.Count();

                var pageSize   = input.PageSize.GetValueOrDefault(10);
                var pageNumber = input.PageNumber.GetValueOrDefault(1) - 1;

                result.Orders = query
                                .OrderBy(o => o.Id)
                                .Skip(pageNumber * pageSize)
                                .Take(pageSize)
                                .ToArray()
                                .Select(o => new OrderOutput(o))
                                .ToArray();

                return(result);
            }
        }