public virtual AssetSearchResponse Owner(string owner) { Assert.IsNotNull(owner, "owner"); var criteriaFilters = new List <AssetCriteriaFilter> { new AssetCriteriaFilter { FieldNameEnum = AssetSearchCriteria.Owner, Value = owner } }; var criteria = new AssetListCriteria { AssetFilter = criteriaFilters }; var results = _dal.GetAssets(criteria); var response = new AssetSearchResponse(); if (results.Any()) { results.ForEach(r => response.Assets.Add(r.AsModel())); } return(response); }
/// <summary> /// The get assets. /// </summary> /// <param name="criteria"> /// The criteria. /// </param> /// <returns> /// The <see cref="IQueryable"/>. /// </returns> /// <exception cref="ApplicationException"> /// Application exception /// </exception> public IQueryable <Asset> GetAssets(AssetListCriteria criteria) { // TODO: Validate Criteria ////throw new ArgumentNullException("criteria", "You must provide a value for the parameter 'criteria'."); try { var predicate = PredicateBuilder.New <Asset>(); foreach (var item in criteria.AssetFilter) { var temp = item.Value; switch (item.FieldNameEnum) { case AssetSearchCriteria.Name: predicate = item.GroupLogicJoin == LogicalJoin.Logical_AND ? predicate.And(Asset.NameLike(temp)) : predicate.Or(Asset.NameLike(temp)); break; case AssetSearchCriteria.InspectionNumber: predicate = item.GroupLogicJoin == LogicalJoin.Logical_AND ? predicate.And(Asset.InspectionNumberLike(temp)) : predicate.Or(Asset.InspectionNumberLike(temp)); break; case AssetSearchCriteria.StructureNumber: predicate = item.GroupLogicJoin == LogicalJoin.Logical_AND ? predicate.And(Asset.StructureNumberLike(temp)) : predicate.Or(Asset.StructureNumberLike(temp)); break; case AssetSearchCriteria.Owner: predicate = item.GroupLogicJoin == LogicalJoin.Logical_AND ? predicate.And(Asset.OwnerLike(temp)) : predicate.Or(Asset.OwnerLike(temp)); break; case AssetSearchCriteria.DeckTypeId: int dtId; if (int.TryParse(temp, out dtId)) { predicate = item.GroupLogicJoin == LogicalJoin.Logical_AND ? predicate.And(Asset.DeckTypeIdEquals(dtId)) : predicate.Or(Asset.DeckTypeIdEquals(dtId)); } break; case AssetSearchCriteria.InspectionDate: DateTime iDate; if (DateTime.TryParse(temp, out iDate)) { predicate = item.GroupLogicJoin == LogicalJoin.Logical_AND ? predicate.And(Asset.InspectionDateEquals(iDate)) : predicate.Or(Asset.InspectionDateEquals(iDate)); } break; default: throw new ApplicationException(string.Format( "An error occurred: {0}", "Unknown AssetListCriteria")); } } return(from asset in this._context.Assets.AsExpandable().Where(predicate) select asset); } catch (Exception ex) { throw new ApplicationException(string.Format( "An error occurred: {0}", ex.Message)); } }