public static IList<Contact> GetContacts(Customer cust) { if (cust == null) return null; if (cust.CustomerID == Guid.Empty) return null; IList<CustomerFacility> customerFacilities = GetFacilities(string.Empty, cust, null); IEnumerable<Contact> result = new List<Contact>(); foreach (CustomerFacility fac in customerFacilities) { result = result.Concat(fac.Contacts); } if (cust.Contact != null) { IList<Contact> director = new List<Contact>(); director.Add(cust.Contact); result = result.Concat(director); } return result.Distinct().ToList(); }
public static IList<CustomerFacility> GetFacilities(string name,Customer customer, Territory territory) { Repository<CustomerFacility, Guid> repo = new Repository<CustomerFacility, Guid>(); var result = repo.GetAll() .Where(fac => fac.Name.Contains(name)); if (customer != null) result = result.Where(fac => fac.Customer.CustomerID == customer.CustomerID); if (territory != null) { result = result.Where(fac => fac.Territory.TerritoryID == territory.TerritoryID); IList<Territory> allTerr = GetAllChildTerritories(territory); allTerr.Add(territory); var allTerrId = from pG in allTerr select pG.TerritoryID; result = from p in result where allTerrId.Contains(p.Territory.TerritoryID) select p; } return result.ToList(); }
public static IList<CustomerFacility> GetFacilitiesForCustomer(Customer customer) { if (customer == null) return null; Repository<CustomerFacility, Guid> repo = new Repository<CustomerFacility, Guid>(); var result = repo.GetAll(); return result.Where(fac => fac.Customer.CustomerID == customer.CustomerID).ToList(); }
public static IList<Order> GetOrders(Customer customer, Employee emp, Territory terr, DateTime? startDate, DateTime? endDate, Dictionary orderStatus) { Repository<Order, Guid> rep = new Repository<Order, Guid>(); var result = from o in rep.GetQueryable() select o; if (customer != null) result = result.Where(o => o.CustomerFacility.Customer == customer); if (emp != null) result = result.Where(o => o.Employee == emp); if (terr != null) result = result.Where(o => o.Territory == terr); if (orderStatus != null) result = result.Where(o => o.OrderStatus == orderStatus); if (startDate.HasValue) result = result.Where(o => o.OrderDate > startDate.Value); if (endDate.HasValue) result = result.Where(o => o.OrderDate < endDate.Value); return result.ToList(); }