private List <IRule> destSelector(List <IRule> RulesApplied, RuntimeData trans) { if (RulesApplied.Where(x => x.CityList.Contains(trans.Destination)).Count() > 0) { RulesApplied = RulesApplied.Where(x => x.CityList.Contains(trans.Destination)).ToList(); } else { State state = UtilityClass.getStateFromCity(trans.Destination); if (state != null && RulesApplied.Where(x => x.StateList.Contains(state.STATE_CODE)).Count() > 0) { RulesApplied = RulesApplied.Where(x => x.StateList.Contains(state.STATE_CODE)).ToList(); } else { ZONE zone = UtilityClass.getZoneFromCityCode(trans.Destination); string zoneCode; if (zone == null) { zoneCode = ""; } else { zoneCode = zone.zcode; } RulesApplied = RulesApplied.Where(x => x.ZoneList.Contains(zoneCode)).ToList(); } } return(RulesApplied); }
internal static ZONE getZoneFromCityCode(string p) { ZONE zone = null; City city = DataSources.CityCopy.SingleOrDefault(x => x.CITY_CODE == p); if (city.ZONE == null || city.ZONE == "") { var state = DataSources.StateCopy.Where(x => x.STATE_CODE == city.CITY_STATE).FirstOrDefault(); if (state != null) { zone = DataSources.ZoneCopy.Where(x => x.zcode == state.STATE_ZONE).FirstOrDefault(); } } else { zone = DataSources.ZoneCopy.Where(x => x.zcode == city.ZONE).FirstOrDefault(); } return(zone); }
private void AddZoneButton_Click(object sender, RoutedEventArgs e) { string errorMsg = ""; BillingDataDataContext db = new BillingDataDataContext(); if (Zonecodebox.Text == "") { errorMsg = errorMsg + "Please enter a proper zone code. \n"; } else { List <ZONE> zones = db.ZONEs.Where(x => x.zcode == Zonecodebox.Text).ToList(); if (zones.Count > 0) { errorMsg = errorMsg + "A zone with this code already exists. \n"; } } if (ZoneNameTextBox.Text == "") { errorMsg = errorMsg + "Please enter a proper zone name. \n"; } if (errorMsg != "") { MessageBox.Show("Please correct the following errors: \n" + errorMsg); return; } ZONE z = new ZONE(); z.Id = Guid.NewGuid(); z.Mode = 'A'; z.Zone_name = this.ZoneNameTextBox.Text; z.zcode = this.Zonecodebox.Text; db.ZONEs.InsertOnSubmit(z); try { db.SubmitChanges(); } catch (Exception ex) { MessageBox.Show(ex.Message); } this.Close(); }