public IResult<IQueryable<IContactSummaryReturn>> GetContacts(FilterContactsParameters parameters) { var parsedResult = parameters.ToParsedParameters(); if(!parsedResult.Success) { return parsedResult.ConvertTo<IQueryable<IContactSummaryReturn>>(); } var predicateResult = ContactPredicateBuilder.BuildPredicate(parsedResult.ResultingObject); if(!predicateResult.Success) { return predicateResult.ConvertTo<IQueryable<IContactSummaryReturn>>(); } var selector = ContactProjectors.SelectSummary(); var query = _companyUnitOfWork.ContactRepository.Filter(predicateResult.ResultingObject).AsExpandable().Select(selector); return new SuccessResult<IQueryable<IContactSummaryReturn>>(query); }
public IResult<IContactSummaryReturn> GetContact(string contactKey) { if(contactKey == null) { throw new ArgumentNullException("contactKey"); } var contactKeyResult = KeyParserHelper.ParseResult<IContactKey>(contactKey); if(!contactKeyResult.Success) { return contactKeyResult.ConvertTo<IContactSummaryReturn>(); } var predicate = new ContactKey(contactKeyResult.ResultingObject).FindByPredicate; var selector = ContactProjectors.SelectSummary(); var contact = _companyUnitOfWork.ContactRepository.Filter(predicate).AsExpandable().Select(selector).SingleOrDefault(); if(contact == null) { return new InvalidResult<IContactSummaryReturn>(null, string.Format(UserMessages.ContactNotFound, contactKey)); } return new SuccessResult<IContactSummaryReturn>(contact); }