private IEnumerable <dynamic> GetRacers()
 {
     using (var f1Context = new Formula1Entities())
     {
         return(GetRacers(f1Context).Skip(_currentPage * PageSize).Take(PageSize).ToList());
     }
 }
예제 #2
0
        public ActionResult SaveWheelChanges(Wheel UpdatedWheel)
        {
            //0. validation
            if (!ModelState.IsValid)
            {
                //over errors for each field in mobdel
                foreach (ModelState S in ModelState.Values)
                {
                    //individual errors for each fields
                }

                //Request.UserHostAddress
                return(View("../Shared/Error")); //error page
            }

            //1. orm
            Formula1Entities FOrm = new Formula1Entities();

            //find
            FOrm.Entry(FOrm.Wheels.Find(UpdatedWheel.WheelID)).CurrentValues.SetValues(UpdatedWheel);

            //save
            FOrm.SaveChanges();

            //go to customer view (refresh customer data)
            return(RedirectToAction("WheelInventory"));
        }
예제 #3
0
 private IEnumerable <F1RaceResult> GetResults()
 {
     using (var f1Context = new Formula1Entities())
     {
         return(GetRaceResults(f1Context).ToList());
     }
 }
예제 #4
0
        public ActionResult WheelInventory()
        {
            Formula1Entities FOrm = new Formula1Entities();

            ViewBag.WheelList = FOrm.Wheels.ToList();

            return(View("WheelInventoryView"));
        }
예제 #5
0
        public ActionResult EngineInventory()
        {
            Formula1Entities FOrm = new Formula1Entities();

            ViewBag.EngineList = FOrm.Engines.ToList();

            return(View("EngineInventoryView"));
        }
예제 #6
0
 private IEnumerable <F1RaceResult> GetRaceResults(Formula1Entities f1Context) =>
 from raceResult in f1Context.RaceResults
     where raceResult.Race.Date == Date
 select new F1RaceResult
 {
     Position = raceResult.Position,
     Racer    = raceResult.Racer.FirstName + " " + raceResult.Racer.LastName,
     Car      = f1Context.Teams.FirstOrDefault(team => team.Id == raceResult.TeamId).Name
 };
 private static IQueryable <dynamic> GetRacers(Formula1Entities f1Context) =>
 from race in f1Context.Races
 from raceResult in race.RaceResults
 orderby race.Date ascending
 select new
 {
     race.Date.Year,
     race.Circuit.Country,
     raceResult.Position,
     Racer = raceResult.Racer.FirstName + " " + raceResult.Racer.LastName,
     Car   = f1Context.Teams.FirstOrDefault(team => team.Id == raceResult.TeamId).Name
 };
예제 #8
0
        public ActionResult AddNewWheel(Wheel newWheel, int WheelID, float Price)
        {
            Formula1Entities FOrm = new Formula1Entities();

            FOrm.Wheels.Add(newWheel);
            FOrm.SaveChanges();

            ViewBag.WheelID = WheelID;
            ViewBag.WCost   = Price;

            return(View("WheelReview"));
        }
예제 #9
0
        //[HttpPost]
        public ActionResult AddNewEngine(Engine newEngine, int EngineID, float Price)
        {
            Formula1Entities FOrm = new Formula1Entities();

            FOrm.Engines.Add(newEngine);
            FOrm.SaveChanges();

            ViewBag.EngineID = EngineID;
            ViewBag.ECost    = Price;

            return(View("EngineReview"));
        }
예제 #10
0
        public ActionResult UpdateWheelById(int WheelID)
        {
            //1. orm
            Formula1Entities FOrm = new Formula1Entities();

            //find
            Wheel ToBeUpdated = FOrm.Wheels.Find(WheelID);

            ViewBag.WheelToBeUpdated = ToBeUpdated;

            return(View("UpdateWheelView"));
        }
예제 #11
0
        public ActionResult UpdateEngineById(int EngineID)
        {
            //1. orm
            Formula1Entities FOrm = new Formula1Entities();

            //find
            Engine ToBeUpdated = FOrm.Engines.Find(EngineID);

            ViewBag.EngineToBeUpdated = ToBeUpdated;

            return(View("UpdateEngineView"));
        }
예제 #12
0
 private static List <Championship> GetYears()
 {
     using (var f1Context = new Formula1Entities())
     {
         return
             (f1Context.Races.Select(race => new Championship {
             Year = race.Date.Year
         })
              .Distinct()
              .OrderBy(championship => championship.Year)
              .ToList());
     }
 }
예제 #13
0
 private IEnumerable <F1Race> GetRaces()
 {
     using (var f1Context = new Formula1Entities())
     {
         return
             ((from race in f1Context.Races
               where race.Date.Year == Year
               orderby race.Date
               select new F1Race
         {
             Date = race.Date,
             Country = race.Circuit.Country
         }).ToList());
     }
 }
예제 #14
0
        public ActionResult DeleteWheelById(int WheelID)
        {
            //1. orm
            Formula1Entities FOrm = new Formula1Entities();

            //2. find what you're looking for THEN remove from list
            //if record has dependencis then delete that first!
            FOrm.Wheels.Remove((FOrm.Wheels.Find(WheelID)));

            //save changes
            FOrm.SaveChanges();

            //show new refreshed database
            return(RedirectToAction("WheelInventory"));
        }
예제 #15
0
        public IEnumerable <dynamic> GetRaces(int aPage, int aPageSize)
        {
            using (var f1Context = new Formula1Entities())
            {
                if (_lastPageSearched == aPage)
                {
                    return(_cache);
                }

                _lastPageSearched = aPage;
                var dynQuery = GetRaces(f1Context).Skip(aPage * aPageSize).Take(aPageSize);
                _cache = dynQuery.ToList();

                return(_cache);
            }
        }