public coreModel.SearchResult SearchStores(coreModel.SearchCriteria criteria)
        {
            var retVal = new coreModel.SearchResult();

            using (var repository = _repositoryFactory())
            {
                var query = repository.Stores;
                if (!string.IsNullOrEmpty(criteria.Keyword))
                {
                    query = query.Where(x => x.Name.Contains(criteria.Keyword) || x.Id.Contains(criteria.Keyword));
                }
                if (!criteria.StoreIds.IsNullOrEmpty())
                {
                    query = query.Where(x => criteria.StoreIds.Contains(x.Id));
                }
                var sortInfos = criteria.SortInfos;
                if (sortInfos.IsNullOrEmpty())
                {
                    sortInfos = new[] { new SortInfo {
                                            SortColumn = "Name"
                                        } };
                }

                query = query.OrderBySortInfos(sortInfos);

                retVal.TotalCount = query.Count();
                var storeIds = query.Skip(criteria.Skip)
                               .Take(criteria.Take)
                               .Select(x => x.Id)
                               .ToArray();

                retVal.Stores = GetByIds(storeIds).AsQueryable().OrderBySortInfos(sortInfos).ToList();
            }
            return(retVal);
        }
Beispiel #2
0
        public webModel.SearchResult SearchStores(coreModel.SearchCriteria criteria)
        {
            var retVal = new webModel.SearchResult();

            //Filter resulting stores correspond to current user permissions
            //first check global permission
            if (!_securityService.UserHasAnyPermission(User.Identity.Name, null, StorePredefinedPermissions.Read))
            {
                //Get user 'read' permission scopes
                criteria.StoreIds = _securityService.GetUserPermissions(User.Identity.Name)
                                    .Where(x => x.Id.StartsWith(StorePredefinedPermissions.Read))
                                    .SelectMany(x => x.AssignedScopes)
                                    .OfType <StoreSelectedScope>()
                                    .Select(x => x.Scope)
                                    .ToArray();
                //Do not return all stores if user don't have corresponding permission
                if (criteria.StoreIds.IsNullOrEmpty())
                {
                    throw new HttpResponseException(HttpStatusCode.Unauthorized);
                }
            }

            var result = _storeService.SearchStores(criteria);

            retVal.TotalCount = result.TotalCount;
            retVal.Stores     = result.Stores.ToArray();
            return(retVal);
        }
 public IHttpActionResult GetStores()
 {
     var criteria = new coreModel.SearchCriteria
     {
          Skip = 0,
          Take = int.MaxValue
     };
     var retVal = SearchStores(criteria);
     return Ok(retVal.Stores);
 }
Beispiel #4
0
        public IHttpActionResult GetStores()
        {
            var criteria = new coreModel.SearchCriteria
            {
                Skip = 0,
                Take = int.MaxValue
            };

            return(Ok(SearchStores(criteria).Stores));
        }
Beispiel #5
0
        public webModel.SearchResult SearchStores(coreModel.SearchCriteria criteria)
        {
            //Filter resulting stores correspond to current user permissions
            //first check global permission
            if (!_securityService.UserHasAnyPermission(User.Identity.Name, null, StorePredefinedPermissions.Read))
            {
                //Get user 'read' permission scopes
                criteria.StoreIds = _securityService.GetUserPermissions(User.Identity.Name)
                                    .Where(x => x.Id.StartsWith(StorePredefinedPermissions.Read))
                                    .SelectMany(x => x.AssignedScopes)
                                    .OfType <StoreSelectedScope>()
                                    .Select(x => x.Scope)
                                    .ToArray();
            }
            var result = _storeService.SearchStores(criteria);
            var retVal = new webModel.SearchResult
            {
                TotalCount = result.TotalCount,
                Stores     = result.Stores.Select(x => x.ToWebModel()).ToArray()
            };

            return(retVal);
        }