public bool ShouldTowCar(ParkingOffense offense, string tag, int zipCode) { List <ParkingTicketDto> ParkingTickets = new List <ParkingTicketDto>(); //Gather Tickets from all states List <IStateParkingAuthority> parkingAuthorities = new List <IStateParkingAuthority> { _MY, _IL, _IN, _PA }; //Note: Imagine if we did all 50 states, and each called a web service. //Todo: We can eventually move this to async calls //Todo: Let's see if we can reduce the number of calls // by changing how we add to the parking tickets object. // Once we hit one state that trips flags for being towed, // no need to keep calling. foreach (IStateParkingAuthority parkingAuthority in parkingAuthorities) { try { ParkingTickets.AddRange(parkingAuthority.GetTicketsFromTag(tag)); } catch (Exception e) { _logger.LogException(e); } } bool shouldTow = _EnforcementRules.ShouldTowCar(ParkingTickets, offense, zipCode); return(shouldTow); }
//Todo: I feel like we should now figure out how to test this. // Previously, I wasn't sure because it was just a // collection, but now that there's two different ones, // I think it is time. public bool ShouldTowCar(List <ParkingTicketDto> existingTickets, ParkingOffense offense, int zipCode) { //Note: We're doing it this way to not invalidate the open/close principle. // There's no business logic here to test though, since it is just a list, // and the business logic is inside the rules. List <TowRule> towRules = new List <TowRule>(); towRules.Add(new TowIfInHandicappedSpot(offense)); towRules.Add(new TowIfTotalFinesEquateMoreThanMaximumAmount(existingTickets.Sum(x => x.Fine))); towRules.Add(new TowIfVehicleHasThreeOrMoreTickets(existingTickets.Count)); towRules.Add(new TowIfSnowOnGround(zipCode)); bool shouldTow = towRules.Any(x => x.ShouldTowCar()); return(shouldTow); }
public bool ShouldTowCar(List <ParkingTicketDto> existingTickets, ParkingOffense offense, int zipCode) { //Note: In the spring, we really don't care about the zip code. // It felt silly thought to create an overload to just point // to another method. //Note: We're doing it this way to not invalidate the open/close principle. // There's no business logic here to test though, since it is just a list, // and the business logic is inside the rules. List <TowRule> towRules = new List <TowRule>(); towRules.Add(new TowIfInHandicappedSpot(offense)); towRules.Add(new TowIfTotalFinesEquateMoreThanMaximumAmount(existingTickets.Sum(x => x.Fine))); towRules.Add(new TowIfVehicleHasThreeOrMoreTickets(existingTickets.Count)); bool shouldTow = towRules.Any(x => x.ShouldTowCar()); return(shouldTow); }
public bool DetermineTicket(ParkingOffense scanOffense, string scanTag) { //Note: We should probably move this into an engine like we have for tows. // It could also determine how much the ticket is for, and handle // warning tickets maybe. bool isTicketableOffense = true; if (scanOffense == ParkingOffense.ExpiredParkingMeter) { //Is It a holiday? var holidays = _holidayService.GetHolidays(); bool isHoliday = holidays.Any( x => x.Date.Month == SystemTime.Now().Month && x.Date.Day == SystemTime.Now().Day); //It is a holiday, we don't charge meters on holiday! isTicketableOffense = !isHoliday; } //We don't want to give a ticket to the same tag, on the same day, for the same thing List <ParkingTicketDto> myStateParkingTickets = _myStateParkingAuthority.GetTicketsFromTag(scanTag); if (myStateParkingTickets.Any(x => x.Offense == scanOffense.ToString() && x.DateOfOffense.Month == SystemTime.Now().Month && x.DateOfOffense.Day == SystemTime.Now().Day && x.DateOfOffense.Year == SystemTime.Now().Year )) { isTicketableOffense = false; } //We Determined they need a parking ticket. if (isTicketableOffense) { _myStateParkingAuthority.IssueParkingTicketDto(scanOffense.ToString(), 30); } return(isTicketableOffense); }
static void Main(string[] args) { ParkingTicketCalculator ptc = new ParkingTicketCalculator(); ParkingOffense myOffense = ParkingOffense.UnknownParkingOffense; //Todo: We have to validate user Input. We could pass ham as an argument // and it shouldn't throw an exception. Maybe consider moving // the parsing to business logic so that we don't have to do this // for the front end. if (Enum.IsDefined(typeof(ParkingOffense), Convert.ToInt32(args[1]))) { myOffense = (ParkingOffense)Convert.ToInt32(args[1]); } string tag = args[0]; //Todo: Probably should have verification on this so that we fail safely // when someone enters ham as a zip. int zip = Convert.ToInt32(args[2]); Console.WriteLine("Parking Offense: " + myOffense.ToString()); Console.WriteLine("Tag: " + tag); Console.WriteLine("Zip Code: " + zip); Console.WriteLine("Scan Started at: " + DateTime.Now.ToString()); string result = ptc.ScanForOffense(new ScanInformation { Offense = myOffense, Tag = tag, zipCode = zip }); Console.WriteLine(Environment.NewLine); Console.WriteLine(result); Console.WriteLine(Environment.NewLine); Console.WriteLine("Scan Done at: " + DateTime.Now.ToString()); Console.WriteLine("Press any key to close."); Console.ReadKey(); }
public TowIfInHandicappedSpot(ParkingOffense offense) { _offense = offense; }