public ActionResult <IEnumerable <HistoryDetailsModel> > Index(long companyId, string searchTerm = null) { var search = new HistorySearchModel(); search.Term = searchTerm; var response = manager.GetIndexModel(companyId, search); return(Ok(response)); }
public IEnumerable <HistoryDetailsModel> GetIndexModel(long companyId, HistorySearchModel search) { var company = dc.Companies.Find(X => X.Id == companyId); if (company == null) { throw new KeyNotFoundException(); } else { var items = dc.Histories.AsQueryable().Where(X => (X.LinkType == HistoriesConsts.LinkType_Company) && (X.LinkId == company.Id)); if (search != null) { if (!string.IsNullOrEmpty(search.Term)) { var words = search.Term.ToUpper().Split(" "); foreach (string word in words) { items = items.Where(X => X.Description.ToUpper().Contains(word)); } } } var response = new List <HistoryDetailsModel>(); foreach (var item in items) { response.Add(new HistoryDetailsModel { HistoryId = item.Id, Description = item.Description, TimeStamp = item.TimeStamp }); } return(response); } }