public ICollection <Models.Location> GetByDate(Models.LocationSearch criteria) { if (criteria.startDate < DateTime.MinValue && criteria.endDate >= DateTime.Now)//valid dates. { throw new Exception("One or more of the dates are not valid."); } try { using (CoronaContext coronaContext = new CoronaContext()) { List <Location> returnObj = new List <Models.Location>(); List <Location> matchLocations = coronaContext.Locations.Where (location => !(criteria.endDate <= location.startDate && criteria.startDate <= location.endDate)).ToList();//-------------------not perfect if (matchLocations.Count() > 0) { Models.Location locationModel = new Models.Location(); returnObj.AddRange(locationModel.ToLocationModel(matchLocations)); } return(returnObj); } } catch (Exception e) { throw new Exception(e.ToString()); } }
public List <Location> Get(LocationSearch locationSearch) { DateTime EmptyDate = new DateTime(); //only location if ((locationSearch.Location != "" || locationSearch.Location != null) && locationSearch.StartDate == EmptyDate && locationSearch.EndDate == EmptyDate) { List <Location> LocationList = _CoronaContext.Location.ToList(); List <Location> searchList = LocationList.FindAll(x => x.Adress.ToLower().Contains(locationSearch.Location.ToLower())); return(searchList); } //only startDate else if (locationSearch.StartDate != EmptyDate && locationSearch.EndDate == EmptyDate && locationSearch.Location == null) { List <Location> LocationList = _CoronaContext.Location.ToList(); List <Location> searchList = LocationList.FindAll(x => x.StartDate >= locationSearch.StartDate); return(searchList); } //only endDate else if (locationSearch.StartDate == EmptyDate && locationSearch.EndDate != EmptyDate && locationSearch.Location == null) { List <Location> LocationList = _CoronaContext.Location.ToList(); List <Location> searchList = LocationList.FindAll(x => x.EndDate <= locationSearch.EndDate); return(searchList); } //start&end date else if (locationSearch.StartDate != EmptyDate && locationSearch.EndDate != EmptyDate && locationSearch.Location == null) { List <Location> LocationList = _CoronaContext.Location.ToList(); List <Location> searchList = LocationList.FindAll(x => x.StartDate >= locationSearch.StartDate && x.EndDate <= locationSearch.EndDate); return(searchList); } //start&end date& location else if (locationSearch.StartDate != EmptyDate && locationSearch.EndDate != EmptyDate && locationSearch.Location != null) { List <Location> LocationList = _CoronaContext.Location.ToList(); List <Location> searchList = LocationList .FindAll(x => x.StartDate >= locationSearch.StartDate && x.EndDate <= locationSearch.EndDate && x.Adress.ToLower().Contains(locationSearch.Location.ToLower())); return(searchList); } //age only /* else if (locationSearch.StartDate != EmptyDate && locationSearch.EndDate != EmptyDate && locationSearch.Location == null&&locationSearch.Age!=null) * { * List<Location> LocationList = _CoronaContext.Location * .Include(L=>L.) * List<Location> searchList = LocationList * .FindAll(x => x.StartDate >= locationSearch.StartDate * && x.EndDate <= locationSearch.EndDate * && x.Adress.ToLower().Contains(locationSearch.Location.ToLower())); * return searchList; * } */ else { throw new Exception(); } }
public List <LocationSearch> ToLocationSearchModel(List <LocationSearch> locationSearch) { List <LocationSearch> returnObj = new List <LocationSearch>(); LocationSearch location = new LocationSearch(); locationSearch.ForEach(l => returnObj.Add(location.ToLocationSearchModel(l))); return(returnObj); }
public List <LocationSearch> ToLocationSearch(List <LocationSearch> locationSearchModel) { List <LocationSearch> returnObj = new List <LocationSearch>(); LocationSearch searchModel = new LocationSearch(); locationSearchModel.ForEach(l => returnObj.Add(searchModel.ToLocationSearch(l))); return(returnObj); }
public LocationSearch ToLocationSearchModel(LocationSearch locationSearch) { return(new LocationSearch() { city = locationSearch.city, age = locationSearch.age, endDate = locationSearch.endDate, startDate = locationSearch.startDate }); }
public List <Location> Get(LocationSearch locationSearch) { throw new NotImplementedException(); }
public ICollection <Models.Location> GetByDate(Models.LocationSearch criteria) { throw new NotImplementedException(); }
//public ICollection<LocationModel> Get(LocationSearchModel locationSearchModel) //{ // try // { // using (CoronaContext coronaContext = new CoronaContext()) // { // if (locationSearchModel.age != 0) // { // List<Patient> patients = coronaContext.Patients.Where(p => p.age == locationSearchModel.age).ToList(); // if (patients.Count() > 0) // { // List<LocationModel> locationsByAge = new List<LocationModel>(); // foreach (var patient in patients) // { // List<Location> locations = coronaContext.Locations.Where(l => l.patientId == patient.id).ToList(); // if (locations.Count() > 0) // { // LocationModel locationModel = new LocationModel(); // locationsByAge.AddRange(locationModel.ToLocationModel(locations)); // } // } // return locationsByAge; // } // } // } // } // catch (Exception e) // { // throw new Exception(e.ToString()); // } // throw new Exception("No locations"); //} //public ICollection<LocationModel> GetByDate(LocationSearchModel criteria) //{ // if (criteria.startDate < DateTime.MinValue && criteria.endDate >= DateTime.Now)//valid dates. // { throw new Exception("One or more of the dates are not valid."); } // try // { // using (CoronaContext coronaContext = new CoronaContext()) // { // List<LocationModel> returnObj = new List<LocationModel>(); // List<Location> matchLocations = coronaContext.Locations.Where // (location => !(criteria.endDate <= location.startDate && criteria.startDate <= location.endDate)).ToList();//-------------------not perfect // if (matchLocations.Count() > 0) // { // LocationModel locationModel = new LocationModel(); // returnObj.AddRange(locationModel.ToLocationModel(matchLocations)); // } // return returnObj; // } // } // catch (Exception e) // { // throw new Exception(e.ToString()); // } //} public ICollection <Models.Location> Get(Models.LocationSearch locationSearch) { throw new NotImplementedException(); }