Пример #1
0
        public async Task <HttpResponseMessage> Get(RackBoxSearchFilter filter)
        {
            if (filter != null)
            {
                var session = (Session)ContextOperator.Get(ContextKeys.SESSION_ID);
                filter.CompanyId = session.CompanyId;
                filter.UserId    = session.UserId;
                var collection = await Task.Run(() => { return(this._rackService.Get(filter)); });

                return(Request.CreateResponse(HttpStatusCode.OK, new ResponseMessage <object>(true, "Succeeded", collection)));
            }
            return(Request.CreateResponse(HttpStatusCode.OK, new ResponseMessage <object>(false, MessageString.INVALID_REQUEST_PARMS, null)));
        }
Пример #2
0
        public IEnumerable <RackBox> Get(RackBoxSearchFilter filter)
        {
            try
            {
                if (filter == null)
                {
                    throw new ArgumentNullException("filter");
                }

                if (string.IsNullOrEmpty(filter.CompanyId))
                {
                    throw new ArgumentNullException("CompanyId");
                }

                if (string.IsNullOrEmpty(filter.Keyword))
                {
                    filter.Keyword = "*";
                }

                if (filter.Take <= 0)
                {
                    filter.Take = 100;
                }

                Expression <Func <RackBox, bool> > predicate = x =>
                                                               x.CompanyId == filter.CompanyId &&
                                                               (filter.Keyword == "*" || x.Name.StartsWith(filter.Keyword));

                if (!string.IsNullOrEmpty(filter.RackId))
                {
                    predicate = predicate.And(x => x.RackId == filter.RackId);
                }

                return(this._rackRepository.Find(predicate).Skip(filter.Start).Take(filter.Take).ToList());
            }
            catch (Exception ex)
            {
                throw;
            }
        }