Exemple #1
0
        public IHttpActionResult Search(coreModel.QuoteRequestSearchCriteria criteria)
        {
            var retVal = _quoteRequestService.Search(criteria);

            return(Ok(new webModel.QuoteRequestSearchResult
            {
                QuoteRequests = retVal.QuoteRequests.Select(x => x.ToWebModel()).ToList(),
                TotalCount = retVal.TotalCount
            }));
        }
        public bool BindModel(System.Web.Http.Controllers.HttpActionContext actionContext, ModelBindingContext bindingContext)
        {
            if (bindingContext.ModelType != typeof(coreModel.QuoteRequestSearchCriteria))
            {
                return(false);
            }

            var qs = HttpUtility.ParseQueryString(actionContext.Request.RequestUri.Query as string);

            var result = new coreModel.QuoteRequestSearchCriteria();

            result.Keyword       = qs["q"].EmptyToNull();
            result.Status        = qs["status"].EmptyToNull();
            result.Tag           = qs["tag"].EmptyToNull();
            result.StoreId       = qs["site"].EmptyToNull();
            result.CustomerId    = qs["customer"].EmptyToNull();
            result.Count         = qs["count"].TryParse(20);
            result.Start         = qs["start"].TryParse(0);
            bindingContext.Model = result;
            return(true);
        }
		public bool BindModel(System.Web.Http.Controllers.HttpActionContext actionContext, ModelBindingContext bindingContext)
		{
			if (bindingContext.ModelType != typeof(coreModel.QuoteRequestSearchCriteria))
			{
				return false;
			}

			var qs = HttpUtility.ParseQueryString(actionContext.Request.RequestUri.Query as string);

			var result = new coreModel.QuoteRequestSearchCriteria();

			result.Keyword = qs["q"].EmptyToNull();
            result.Status = qs["status"].EmptyToNull();
            result.Tag = qs["tag"].EmptyToNull();	
			result.StoreId = qs["site"].EmptyToNull();
			result.CustomerId = qs["customer"].EmptyToNull();
			result.Count = qs["count"].TryParse(20);
			result.Start = qs["start"].TryParse(0);
			bindingContext.Model = result;
			return true;
		}
        public QuoteRequestSearchResult Search(QuoteRequestSearchCriteria criteria)
        {
            QuoteRequestSearchResult retVal = null;
            using (var repository = _repositoryFactory())
            {
                var query = repository.QuoteRequests;
                if (criteria.CustomerId != null)
                {
                    query = query.Where(x => x.CustomerId == criteria.CustomerId);
                }
                if (criteria.StoreId != null)
                {
                    query = query.Where(x => x.StoreId == criteria.StoreId);
                }

                if(criteria.Number != null)
                {
                    query = query.Where(x => x.Number == criteria.Number);
                }
                else if(criteria.Keyword != null)
                {
                    query = query.Where(x => x.Number.Contains(criteria.Keyword));
                }

                if(criteria.Tag != null)
                {
                    query = query.Where(x => x.Tag == criteria.Tag);
                }
                if (criteria.Status != null)
                {
                    query = query.Where(x => x.Status == criteria.Status);
                }
                var ids = query.OrderByDescending(x => x.CreatedDate)
                               .Skip(criteria.Start)
                               .Take(criteria.Count)
                               .Select(x => x.Id)
                               .ToArray();

                retVal = new QuoteRequestSearchResult
                {
                    TotalCount = query.Count(),
                    QuoteRequests = GetByIds(ids).ToList()
                };

            }
            return retVal;
        }
        public IHttpActionResult Search([ModelBinder(typeof(SearchCriteriaBinder))] coreModel.QuoteRequestSearchCriteria criteria)
        {
            var retVal = _quoteRequestService.Search(criteria);

            return(Ok(retVal));
        }