public int compareTo( Donation another ) { // -1 if this is < another // 0 if they are equivilent // +1 if this is > another //if( ) { return 0; //} }
public void assignPickup( Donation donation ) { if( donation != default(Donation) ) { status = "assigned"; pickup = donation; } else { // throw error } }
public void addDonation( Donation donation ) { this.donation = donation; }
public Driver( string uname, string upass, GPS loc ) : base(uname, upass, "Driver", loc) { pickup = null; dropoff = null; }
public Driver() : base("","","Driver",null) { pickup = null; dropoff = null; }
public string submitDonation( string authenToken, string pickupContactName, string pickupContactPhone, string pickupExtraDetails, int pickupLatitude, int pickupLongitude ) { Dictionary<String, Tuple<User,String>> users = ((Dictionary<String, Tuple<User,String>>)appState ["users"]); if (users == null) { users = new Dictionary<string, Tuple<User, string>> (); return "No Users"; } if (!users.ContainsKey (authenToken)) { return "User Doesn't Exist"; } User uTmp = users[authenToken].Item1; if( uTmp.getRole() == "Donor" ) { Donation new_donation = new Donation(pickupContactName, pickupContactPhone, pickupExtraDetails, pickupLatitude, pickupLongitude, (Donor)uTmp, (int)((DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalSeconds)); ((Donor)uTmp).addDonation(new_donation); Driver driver = ((Donor)uTmp).findBestDriver( ((List<Driver>)appState["drivers"]).ToArray() ); if( driver != default(Driver) ) { // There is at least one driver available Receiver dropoff = ((Donor)uTmp).findBestDropOff( ((List<Receiver>)appState["receivers"]).ToArray() ); if( dropoff != default(Receiver) ) { // There is at least one reciever driver.assignPickup(new_donation); driver.assignDropoff(dropoff); driver.updateStatus("assigned"); testPush(driver.authToken,"Donation Available"); } else { // No drop-off. what do? return "User is empty?"; } } else { ((List<Donor>)appState["activeDonations"]).Add((Donor)uTmp); Queue_t<Donation> queue = (Queue_t<Donation>)appState["queue"]; queue.insert( new Pair_t(new_donation.getEpoch(), new_donation) ); return "No Driver Available"; } return "Pushing Donation"; } else { return "Donating as a non-Donator"; } }