Пример #1
0
        public async Task <HttpResponseMessage> Get(RackSearchFilter 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 <Rack> Get(RackSearchFilter 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 <Rack, bool> > predicate = x =>
                                                            x.CompanyId == filter.CompanyId && x.Status == (byte)StatusType.Active &&
                                                            (filter.Keyword == "*" || x.Name.StartsWith(filter.Keyword));

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

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