using System; using System.Collections.Generic; using System.Linq; using System.Web; using Weee.Models; using Weee.Models.ExtensionMethods; using Weee.Models.Paramemter; using Weee.ViewModels; namespace Weee.Supports { public class DataFilter { public List FilterLca(IEnumerable lcas, string searchString) { var filteredLcas = new List(); if (searchString == "") { return lcas.ToList(); } foreach (var lca in lcas) { var ownerName = lca.Owner == null ? "" : lca.Owner.Name; var verifyBy = lca.VerifyBy == null ? "" : lca.VerifyBy.Name; //DL-19 begin var description = lca.Description == null ? "" : lca.Description ; var createdDate = lca.CreatedDate == null ? null : lca.CreatedDate.ToString(); var startDate = lca.StartDate == null ? null : lca.StartDate.ToString(); var endDate = lca.EndDate == null ? null : lca.EndDate.ToString(); var deadLine = lca.DeadLine == null ? null : lca.DeadLine.ToString(); var lcaTypeDisplayName = lca.LCATypeDisplayName == null ? "" : lca.LCATypeDisplayName.ToString(); var status = lca.Status + ""; var toBeSearch = (ownerName + " " + verifyBy + " " + description+ " " + createdDate + " " + startDate + " " + endDate + " " + deadLine + " " + lcaTypeDisplayName + " " + status).ToLower(); //var toBeSearch = (ownerName + " " + // verifyBy + " " + // lca.Description.ToString() + " " + // lca.CreatedDate.ToString() + " " + // lca.StartDate.ToString() + " " + // lca.EndDate.ToString() + " " + // lca.DeadLine.ToString() + " " + // lca.LCATypeDisplayName + " " + // lca.Status.ToString()).ToLower(); //end if (toBeSearch.Contains(searchString.ToLower())) { filteredLcas.Add(lca); } } return filteredLcas; } public List FilterCompany(List companies, string searchString) { var filteredCompanies = new List(); if (searchString == "") { return companies; } foreach (var company in companies) { var toBeSearch = (company.Name + " " + company.Address + " " + company.Status.DisplayString() + " " + company.CompanyTypeDisplayName).ToLower(); if (toBeSearch.Contains(searchString.ToLower())) { filteredCompanies.Add(company); } } return filteredCompanies; } public List FilterCompany(List companies, string searchString) { var filteredCompanies = new List(); if (searchString == "") { return companies; } foreach (var company in companies) { var toBeSearch = (company.Name + " " + company.Address + " " + company.Status.DisplayString() + " " + company.CompanyTypeDisplayName).ToLower(); if (toBeSearch.Contains(searchString.ToLower())) { filteredCompanies.Add(company); } } return filteredCompanies; } public List FilterNonYearlyParameterType(List nonYearlyParameterTypes, string searchString) { var filteredNonYearlyParameterTypes = new List(); if (searchString == "") { return nonYearlyParameterTypes; } foreach (var nonYearlyParameterType in nonYearlyParameterTypes) { var parameterValue = nonYearlyParameterType.Parameters.Count != 0 ? nonYearlyParameterType.Parameters.First().Value.ToString() : ""; var toBeSearch = (nonYearlyParameterType.DisplayName + " " + nonYearlyParameterType.Category.DisplayName + " " + parameterValue).ToLower(); if (toBeSearch.Contains(searchString.ToLower())) { filteredNonYearlyParameterTypes.Add(nonYearlyParameterType); } } return filteredNonYearlyParameterTypes; } public List FilterProduct(IEnumerable products, string searchString) { var filteredProducts = new List(); if (searchString == "") { return products.ToList(); } foreach (var product in products) { var toBeSearch = (product.Name + " " + product.SpecDescription + " " + product.SerialNumber).ToLower(); if (toBeSearch.Contains(searchString.ToLower())) { filteredProducts.Add(product); } } return filteredProducts; } public List FilterFab(IEnumerable fabs, string searchString) { var filteredFabs = new List(); if (searchString == "") { return fabs.ToList(); } foreach (var fab in fabs) { var toBeSearch = (fab.Name + " " + fab.Phone + " " + fab.Address).ToLower(); if (toBeSearch.Contains(searchString.ToLower())) { filteredFabs.Add(fab); } } return filteredFabs; } } }