public DTOResponse <List <DTOPartner> > GetAll(DTOPartnerSearch searchQuery) { return(_domain.GetAll(searchQuery)); }
public DTOResponse <List <DTOPartner> > GetAll(DTOPartnerSearch searchQuery) { var filter = Builders <PartnerModel> .Filter.Ne(x => x.Id, null); switch (searchQuery.Column) { case PartnerSearchColumn.Name: { filter = Builders <PartnerModel> .Filter.Where(model => model.Name.ToLower().Contains(searchQuery.Term.ToLower())); break; } case PartnerSearchColumn.City: { filter = Builders <PartnerModel> .Filter.Where(model => model.City.ToLower().Contains(searchQuery.Term.ToLower())); break; } case PartnerSearchColumn.Country: { filter = Builders <PartnerModel> .Filter.Where(model => model.Country.ToLower().Contains(searchQuery.Term.ToLower())); break; } case PartnerSearchColumn.Email: { filter = Builders <PartnerModel> .Filter.Where(model => model.Email1.ToLower().Contains(searchQuery.Term.ToLower()) || model.Email2.ToLower().Contains(searchQuery.Term.ToLower())); break; } case PartnerSearchColumn.Tel: { filter = Builders <PartnerModel> .Filter.Where(model => model.Tel1.ToLower().Contains(searchQuery.Term.ToLower()) || model.Tel2.ToLower().Contains(searchQuery.Term.ToLower())); break; } case PartnerSearchColumn.HasNotes: { if (searchQuery.Term == "1") { filter = Builders <PartnerModel> .Filter.Where(model => model.Notes != null && model.Notes != ""); } else { filter = Builders <PartnerModel> .Filter.Where(model => model.Notes == null || model.Notes == ""); } break; } case PartnerSearchColumn.ShowInApp: { var showInApp = searchQuery.Term == "1"; filter = Builders <PartnerModel> .Filter.Where(model => model.ShowInApp == showInApp); break; } case PartnerSearchColumn.SubscriptionLevel: { var subscriptionLevel = int.Parse(searchQuery.Term); filter = Builders <PartnerModel> .Filter.Where(model => model.SubscriptionLevel == subscriptionLevel); break; } case PartnerSearchColumn.InfoStatus: { var infoStatus = int.Parse(searchQuery.Term); filter = Builders <PartnerModel> .Filter.Where(model => model.InfoStatus == infoStatus); break; } } var foundModelList = _collection.Find <PartnerModel>(filter).Skip(searchQuery.Offset).Limit(searchQuery.Size).SortBy(model => model.Name).ToList(); var totalDocuments = _collection.Find <PartnerModel>(filter).CountDocuments(); var foundDTOList = new List <DTOPartner>(); foreach (var model in foundModelList) { var dto = model.ToDTO(); this.LoadPartnerData(dto, model); foundDTOList.Add(dto); } return(new DTOResponse <List <DTOPartner> >() { Code = 200, Data = foundDTOList, Total = totalDocuments }); }