public bool deleteRace(int raceID)
        {
            bool isDeleted = false;
            var db = new MXEugeneDBContext();
            Race fRace = db.Races.Where(r => r.RaceID == raceID).FirstOrDefault<Race>();
            if (fRace != null)
            {
                foreach( Class c in fRace.Class)
                {
                    List<Rider> testlist = c.Rider;
                    if (c.Rider.Count != 0)
                    {
                        c.Rider.Clear();
                        /*foreach (Rider r in c.Rider)
                        {
                            c.Rider.Remove(r);
                        }*/
                    }

                }
                if(fRace.Class != null)
                {
                    fRace.Class.Clear();
                }

                db.Races.Remove(fRace);
                db.SaveChanges();
                isDeleted = true;
            }
            return isDeleted;
        }
 public bool deleteBike(int bikeID)
 {
     bool isDeleted = false;
     var db = new MXEugeneDBContext();
     Bike fBike = db.Bikes.Where(b => b.BikeID == bikeID).FirstOrDefault<Bike>();
     if (fBike != null)
     {
         db.Bikes.Remove(fBike);
         db.SaveChanges();
         isDeleted = true;
     }
     return isDeleted;
 }
 public bool addRiderToClass(int classID, int riderID)
 {
     bool isAdded = false;
     var db = new MXEugeneDBContext();
     Rider fRider = db.Riders.Where(r => r.RiderID == riderID).FirstOrDefault<Rider>();
     Class fClass = db.Classes.Where(c => c.ClassID == classID).FirstOrDefault<Class>();
     if(fClass != null)
     {
         fClass.Rider.Add(fRider);
         db.SaveChanges();
         isAdded = true;
     }
     return isAdded;
 }
 public bool addLicense(License license)
 {
     bool isLicenseAdded = false;
     var db = new MXEugeneDBContext();
     Rider fRider = db.Riders.Where(r => r.RiderID == license.Rider.RiderID).FirstOrDefault<Rider>();
     if (Rider != null)
     {
         license.Rider = fRider;
         db.Licenses.Add(license);
         db.SaveChanges();
         isLicenseAdded = true;
     }
     return isLicenseAdded;
 }
 public bool addBike(Bike bike)
 {
     bool isBikeAdded = false;
     var db = new MXEugeneDBContext();
     Rider fRider = db.Riders.Where(r => r.RiderID == bike.Rider.RiderID).FirstOrDefault<Rider>();
     if (Rider != null)
     {
         bike.Rider = fRider;
         db.Bikes.Add(bike);
         db.SaveChanges();
         isBikeAdded = true;
     }
     return isBikeAdded;
 }
 public bool addRider(Rider rider)
 {
     bool isAdded = false;
     var db = new MXEugeneDBContext();
     Rider fRider = (from r in db.Riders
                     where r.FName == rider.FName &&
                     r.LName == rider.LName
                     select r).FirstOrDefault<Rider>();
     if (fRider == null)
     {
         db.Riders.Add(rider);
         db.SaveChanges();
         isAdded = true;
     }
     return isAdded;
 }
        public bool addRace(Race race)
        {
            bool isAdded = false;
            var db = new MXEugeneDBContext();
            Race fRace = (from r in db.Races
                          where r.Title == race.Title &&
                          r.Date == race.Date
                          select r).FirstOrDefault<Race>();
            if(fRace == null)
            {
                db.Races.Add(race);
                db.SaveChanges();
                isAdded = true;
            }

            return isAdded;
        }
 public bool editRace(Race race)
 {
     bool isUpdated = false;
     var db = new MXEugeneDBContext();
     Race fRace = db.Races.Where(r => r.RaceID == race.RaceID).FirstOrDefault<Race>();
     if(fRace != null)
     {
         fRace.Title = race.Title;
         fRace.Descrtiption = race.Descrtiption;
         fRace.Date = race.Date;
         fRace.Class = race.Class;
         db.SaveChanges();
         isUpdated = true;
     }
     return isUpdated;
 }
 public bool deleteLicense(int licenseID)
 {
     bool isDeleted = false;
     var db = new MXEugeneDBContext();
     License fLicenses = db.Licenses.Where(l => l.LicenseID == licenseID).FirstOrDefault<License>();
     if (fLicenses != null)
     {
         db.Licenses.Remove(fLicenses);
         db.SaveChanges();
         isDeleted = true;
     }
     return isDeleted;
 }
        public bool editRider(Rider rider)
        {
            bool isUpdated = false;
            var db = new MXEugeneDBContext();
            Rider fRider = db.Riders.Where(r => r.RiderID == rider.RiderID).FirstOrDefault<Rider>();
            if (fRider != null)
            {
                fRider.FName = rider.FName;
                fRider.LName = rider.LName;
                fRider.EMail = rider.EMail;
                fRider.City = rider.City;
                fRider.State = rider.State;
                fRider.Zip = rider.Zip;
                fRider.Phone = rider.Phone;
                fRider.DOB = rider.DOB;
                fRider.Age = rider.Age;
                fRider.ReleaseSigned = rider.ReleaseSigned;
                fRider.ParentReleaseSigned = rider.ParentReleaseSigned;

                db.SaveChanges();
                isUpdated = true;
            }
            return isUpdated;
        }
 public bool editLicense(License license)
 {
     bool isUpdated = false;
     var db = new MXEugeneDBContext();
     License fLicense = db.Licenses.Where(l => l.LicenseID == license.LicenseID).FirstOrDefault<License>();
     if (fLicense != null)
     {
         fLicense.LicenseType = license.LicenseType;
         fLicense.District = license.District;
         fLicense.Classification = license.Classification;
         fLicense.DateIssued = license.DateIssued;
         fLicense.DateExpires = license.DateExpires;
         fLicense.Rider = license.Rider;
         db.SaveChanges();
         isUpdated = true;
     }
     return isUpdated;
 }
 public bool editBike(Bike bike)
 {
     bool isUpdated = false;
     var db = new MXEugeneDBContext();
     Bike fBike = db.Bikes.Where(b => b.BikeID == bike.BikeID).FirstOrDefault<Bike>();
     if (fBike != null)
     {
         fBike.BikeID = bike.BikeID;
         fBike.BikeNum = bike.BikeNum;
         fBike.Make = bike.Make;
         fBike.Model = bike.Model;
         db.SaveChanges();
         isUpdated = true;
     }
     return isUpdated;
 }
        public bool deleteRider(int riderID)
        {
            bool isDeleted = false;
            var db = new MXEugeneDBContext();
            Rider fRider = db.Riders.Where(r => r.RiderID == riderID).FirstOrDefault<Rider>();
            if (fRider != null)
            {
                // need to remove bikes and linces from rider befor deleting the rider
                /*var Bikes = db.Bikes.Where(b => b.Rider.RiderID == fRider.RiderID).AsQueryable();
                List<License> Licenses = db.Licenses.Where(l => l.rider == fRider).ToList<License>();
                if(Bikes != null)
                {
                    foreach(Bike b in Bikes)
                    {
                        db.Bikes.Remove(b);
                    }
                }
               if (Licenses != null)
                {
                    foreach (License l in Licenses)
                    {
                        db.Licenses.Remove(l);
                    }
                }*/

                db.Riders.Remove(fRider);
                db.SaveChanges();
                isDeleted = true;
            }
            return isDeleted;
        }