public List <PitStop> CreatePitStopList(PitStop pitStop, string currentUser) { if (pitStop.PitStopID > 0) { PitStop editPitStops = db.PitStops.SingleOrDefault(x => x.PitStopID == pitStop.PitStopID); editPitStops.PitStopName = pitStop.PitStopName; editPitStops.SequenceNumber = pitStop.SequenceNumber; editPitStops.Address = pitStop.Address; editPitStops.LastModifiedBy = currentUser; editPitStops.LastModifiedAt = DateTime.Now; db.SaveChanges(); pitStop.CreatedBy = currentUser; //db.PitStops.Add(pitStop); db.SaveChanges(); } else { pitStop.CreatedBy = currentUser; db.PitStops.Add(pitStop); db.SaveChanges(); } return(db.PitStops.ToList()); }
public async System.Threading.Tasks.Task <ActionResult> AddPitStop(PitStop pitStop) { UserManager <TARUser> UserManager = new UserManager <TARUser>(new UserStore <TARUser>(new TARDBContext())); List <PitStop> pitStops = new List <PitStop>(); int eventId = Convert.ToInt32(Session["eventId"]); String currentUser = User.Identity.GetUserName(); var user = await UserManager.FindByNameAsync(pitStop.Staff.UserName); var userId = user.Id; db.PitStops.Add(pitStop); pitStops = pitStopBAL.CreatePitStopList(pitStop, currentUser, eventId, userId); List <SelectListItem> ListOfUsers = new List <SelectListItem>(); var getRole = (from r in db.Roles where r.Name.Contains("Staff") select r).FirstOrDefault(); var getStaffUsers = db.Users.Where(x => x.Roles.Select(y => y.RoleId).Contains(getRole.Id)).ToList(); foreach (var item in getStaffUsers) { ListOfUsers.Add(new SelectListItem() { Text = item.UserName, Value = item.UserName }); } ViewBag.StaffList = ListOfUsers; Response.StatusCode = 202; return(PartialView("_Index", pitStops)); }
public ActionResult Edit(int id, PitStop acePitStop) { try { // TODO: Add update logic here PitStop pitstop = unitOfWork.PitStops.Get(acePitStop.Id); UpdateModel(pitstop); unitOfWork.Complete(); return(RedirectToAction("Index", "Event")); } catch (Exception e) { if (e.GetType() != typeof(DbEntityValidationException)) { if (this.HttpContext.IsDebuggingEnabled) { ModelState.AddModelError(string.Empty, e.ToString()); } else { ModelState.AddModelError(string.Empty, "Some technical error happened."); } } return(View()); } }
public ActionResult Create(PitStop PitStop) { try { if (ModelState.IsValid) { rep.Create(PitStop); rep.Save(); return(RedirectToAction("Index")); } } catch (Exception exp) { if (exp.GetType() != typeof(DbEntityValidationException)) { if (this.HttpContext.IsDebuggingEnabled) { ModelState.AddModelError(String.Empty, exp.ToString()); } else { ModelState.AddModelError(String.Empty, "Some error has occured"); } } } return(View(PitStop)); }
public ActionResult Edit(PitStop acePitStop) { IEnumerable <Event> List = unitOfWork.Events.GetAll(); PitStop EventPitStop = unitOfWork.PitStops.Get(acePitStop.Id); ViewBag.EventID = new SelectList(List, "Id", "Name", EventPitStop.EventID); return(View(EventPitStop)); }
public ActionResult DeleteConfirmed(int id) { PitStop pitStop = db.PitStops.Find(id); db.PitStops.Remove(pitStop); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Create() { IEnumerable <Event> List = unitOfWork.Events.GetAll(); ViewBag.EventID = new SelectList(List, "Id", "Name"); PitStop pitstop = new PitStop(); return(View(pitstop)); }
/*<summary> * Delets PitStop from DB * </summary> * * <returns> * list of pitstops for the event Id * </returns>*/ /// <param name="pitStopId"></param> /// <param name="eventId"></param> public List <PitStop> DeletePitStopfromList(int pitStopId, int eventId) { var pitStop = db.PitStops.Find(pitStopId); PitStop stops = db.PitStops.SingleOrDefault(x => x.PitStopID == pitStopId); db.PitStops.Remove(stops); db.SaveChanges(); //result = true; return(getPitStopOfEvent(eventId)); }
/*<summary> * Fetch pitStop Details for the given pitStopId to edit pitStop * </summary> * <returns> * single pitStop object * </returns>*/ /// <param name="pitStopId"></param> public PitStop GetValuesToEdit(int pitStopId) { PitStop editPitStops = db.PitStops.SingleOrDefault(x => x.PitStopID == pitStopId); pitStop.PitStopID = editPitStops.PitStopID; pitStop.PitStopName = editPitStops.PitStopName; pitStop.Address = editPitStops.Address; pitStop.SequenceNumber = editPitStops.SequenceNumber; return(pitStop); }
public ActionResult Delete(PitStop PitStop) { try { //yet to be written return(RedirectToAction("Index")); } catch { return(View()); } }
// GET: PitStop/Create public ActionResult Create() { PitStop pitstop1 = new PitStop(); IEnumerable <SelectListItem> items = db.Event.Select(c => new SelectListItem { Value = c.EventId.ToString(), Text = c.EventId.ToString() }); ViewBag.EventNameList = items; return(View()); }
public ActionResult Edit([Bind(Include = "PitStopID,EventID,StopName,StopOrder,Location,StaffID")] PitStop pitStop) { if (ModelState.IsValid) { db.Entry(pitStop).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.EventID = new SelectList(db.Events, "EventID", "EventName", pitStop.EventID); ViewBag.StaffID = new SelectList(db.Staffs, "StaffID", "StaffCode", pitStop.StaffID); return(View(pitStop)); }
public void Setup() { _machine = new PitStop(); _instance = new PitStopInstance(); var vehicle = new Vehicle { Make = "Audi", Model = "A6", }; _machine.RaiseEvent(_instance, _machine.VehicleArrived, vehicle).Wait(); }
public ActionResult Edit(PitStop PitStop) { if (ModelState.IsValid) { rep.Update(PitStop); rep.Save(); return(RedirectToAction("Index")); } else { return(View(PitStop)); } }
public void AddPitStops(String[] pitstops, String eventId) { for (int pitIndex = 0; pitIndex < pitstops.Length; pitIndex++) { System.Diagnostics.Debug.WriteLine(pitstops[pitIndex]); PitStop pitstop = new PitStop(); pitstop.PitStopLocation = pitstops[pitIndex]; pitstop.PitStopName = pitstops[pitIndex]; pitstop.EventId = Int32.Parse(eventId); pitstop.PitStopOrder = pitIndex + 1; db.Pitstop.Add(pitstop); db.SaveChanges(); } }
// GET: PitStop/Details/5 public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } PitStop pitStop = db.PitStops.Find(id); if (pitStop == null) { return(HttpNotFound()); } return(View(pitStop)); }
// GET: PitStop/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } PitStop pitStop = db.PitStops.Find(id); if (pitStop == null) { return(HttpNotFound()); } ViewBag.EventID = new SelectList(db.Events, "EventID", "EventName", pitStop.EventID); ViewBag.StaffID = new SelectList(db.Staffs, "StaffID", "StaffCode", pitStop.StaffID); return(View(pitStop)); }
public ActionResult Edit(PitStop pit) { try { pit.UpdatedOn = DateTime.Now; pit.UpdatedById = User.Identity.GetUserId(); pitStopService.Update(pit); TempData["MessageAlert"] = new Alert { CssClass = "alert-success", Title = "Success!", Message = "Pit Stop is successfully updated." }; return(RedirectToAction("Edit", new { id = pit.Id })); } catch { return(View(pit)); } }
public ActionResult Create(PitStop pit) { try { pit.CreatedOn = DateTime.Now; pit.CreatedById = User.Identity.GetUserId(); pitStopService.Add(pit); TempData["MessageAlert"] = new Alert { CssClass = "alert-success", Title = "Success!", Message = "Race event is successfully created." }; return(RedirectToAction("Create")); } catch { return(View()); } }
RaceStrategy[] TestPitStopSimulation(int[] driversToPit, float[] cumulativeTimes) { float pitStopLoss = 21F; int numberOfStrategies = 3; int trackIndex = 14; RaceStrategy[] strategies = SetupStrategiesForPitStopSimulation(trackIndex, numberOfStrategies); strategies = SetupRaceForPitStopSimulation(strategies, cumulativeTimes); List <PitStop> pitstops = new List <PitStop>(); foreach (int driver in driversToPit) { pitstops.Add(new PitStop(driver, 1, pitStopLoss)); } PitStop.UpdateRacePositionsAfterPitStop(ref strategies, pitstops); return(strategies); }
/*<summary> * Create and edit pitStops for the eventId * </summary> * <returns> * List of pitStops created/updated * </returns>*/ /// <param name="pitStop"></param> /// <param name="currentUser"></param> /// <param name="eventId"></param> /// <param name="userId"></param> public List <PitStop> CreatePitStopList(PitStop pitStop, string currentUser, int eventId, string userId) { if (pitStop.PitStopID > 0) { PitStop editPitStops = db.PitStops.SingleOrDefault(x => x.PitStopID == pitStop.PitStopID); editPitStops.PitStopName = pitStop.PitStopName; editPitStops.SequenceNumber = pitStop.SequenceNumber; editPitStops.Address = pitStop.Address; editPitStops.Latitude = pitStop.Latitude; editPitStops.Longitude = pitStop.Longitude; editPitStops.LastModifiedBy = currentUser; Event currentEvent = db.Events.SingleOrDefault(x => x.EventID == eventId); pitStop.Event = currentEvent; TARUser staffInfo = db.Users.FirstOrDefault(d => d.Id == userId); editPitStops.Staff = staffInfo; editPitStops.LastModifiedAt = DateTime.Now; db.SaveChanges(); pitStop.CreatedBy = currentUser; //db.PitStops.Add(pitStop); db.SaveChanges(); } else { pitStop.CreatedBy = currentUser; pitStop.Staff.Id = userId; Event currentEvent = db.Events.SingleOrDefault(x => x.EventID == eventId); TARUser staffInfo = db.Users.FirstOrDefault(d => d.Id == userId); pitStop.Staff = staffInfo; pitStop.Event = currentEvent; db.PitStops.Add(pitStop); db.SaveChanges(); } return(getPitStopOfEvent(eventId)); }
public ActionResult Create(PitStop pitstop) { try { unitOfWork.PitStops.Add(pitstop); unitOfWork.Complete(); return(RedirectToAction("Index", "Event")); } catch (Exception e) { if (e.GetType() != typeof(DbEntityValidationException)) { if (this.HttpContext.IsDebuggingEnabled) { ModelState.AddModelError(string.Empty, e.ToString()); } else { ModelState.AddModelError(string.Empty, "Some technical error happened."); } } return(View()); } }
public ActionResult Delete(int id, PitStop pitstop1) { try { rep.DeletePitStop(id); rep.Save(); // TODO: Add delete logic here return(RedirectToAction("Index")); } catch (Exception e) { if (this.HttpContext.IsDebuggingEnabled) { ModelState.AddModelError(string.Empty, e.ToString()); } else { ModelState.AddModelError(string.Empty, "Some technical error happened."); } return(View()); } }
public async Task <ActionResult <PitStop> > Put(int id, [FromBody] PitStop value) { return(await this.baseController.Put(id, value)); }
public async Task <ActionResult <PitStop> > Post([FromBody] PitStop value) { return(await this.baseController.Post(value)); }
public void DeletePitStop(int id) { PitStop pitstop1 = db.Pitstop.Single(m => m.PitStopId == id); db.Pitstop.Remove(pitstop1); }
public void AddPitstop(PitStop pitstoprep) { db.Pitstop.Add(pitstoprep); }
// GET: PitStops/Details/5 public ActionResult Details(PitStop acePitStop) { PitStop EventPitStop = unitOfWork.PitStops.Get(acePitStop.Id); return(View(EventPitStop)); }
internal void Update(SessionResult session, Simulation sim) { foreach (var result in session.Results.OfType <EntitySessionResult>()) { if (result.Entity.Results.CurrentResult == null || result.Entity.Results.CurrentResult.Session.Id != session.Id) { ((EntityResults)result.Entity.Results).CurrentResult = result; } var prevPos = result.PrevTrackPct; var curPos = sim.Telemetry.CarIdxLapDistPct[result.Entity.CarIdx]; var now = Updater.CurrentTime - curPos / (1 + curPos - prevPos) * (Updater.CurrentTime - Updater.PrevTime); var movement = result.Entity.Car.Movement as CarMovement; var prevLap = result.PrevLapNumber; var curLap = sim.Telemetry.CarIdxLapCompleted[result.Entity.CarIdx]; result.PrevLapNumber = curLap; result.PrevTrackPct = curPos; result.PrevTrackPctUpdate = Updater.CurrentTime; if (Updater.CurrentTime <= result.PrevTrackSpeedPctUpdate || Math.Abs(curPos - prevPos) < 10E-6) { movement.Speed = 0; movement.IsAccelerating = false; movement.IsBraking = true; goto CalcPitStop; } var diff = Updater.CurrentTime - result.PrevTrackSpeedPctUpdate; if (diff >= SpeedCalcInterval) { CalcSpeed(movement, curPos, result.PrevTrackSpeedPct, diff, sim.Session.Track.Length); result.PrevTrackSpeedPct = curPos; result.PrevTrackSpeedPctUpdate = Updater.CurrentTime; } movement.Gear = sim.Telemetry.CarIdxGear[result.Entity.CarIdx]; movement.Rpm = (int)sim.Telemetry.CarIdxRPM[result.Entity.CarIdx]; if (!result.Finished && sim.Telemetry.CarIdxTrackSurface[result.Entity.CarIdx] != TrackLocation.NotInWorld) { result.CurrentTrackPct = sim.Telemetry.CarIdxLap[result.Entity.CarIdx] + sim.Telemetry.CarIdxLapDistPct[result.Entity.CarIdx] - 1; movement.TrackPct = (float)result.CurrentTrackPct % 1; // Update current lap properties UpdateCurrentLap(result, session); UpdateSector(sim, session, result, curPos, prevPos); //if (curPos < 0.1 && prevPos > 0.9 && movement.Speed > 0) if (curLap > prevLap) { OnFinishCrossing(sim.Telemetry, result, now, session, curLap + 1); } } if (result.CurrentLap.Number + result.CurrentLap.GapLaps > session.FinishLine && sim.Telemetry.CarIdxTrackSurface[result.Entity.CarIdx] != TrackLocation.NotInWorld && session.Type == SessionType.Race && !result.Finished) { result.Finished = true; result.CurrentTrackPct = Math.Floor(result.CurrentTrackPct) + 0.0064 - 0.0001 * result.Position; ((CarMovement)result.Entity.Car.Movement).TrackPct = (float)result.CurrentTrackPct % 1; } UpdateTrackLocation(sim, result, sim.Telemetry.CarIdxTrackSurface[result.Entity.CarIdx]); CalcPitStop: var inPitStall = movement.TrackLocation == TrackLocation.InPitStall; movement.IsInPits = sim.Telemetry.CarIdxOnPitRoad[result.Entity.CarIdx] || inPitStall || movement.TrackLocation == TrackLocation.NotInWorld; if (movement.TrackLocation == TrackLocation.NotInWorld || session.Type != SessionType.Race || session.State != SessionState.Racing) { continue; } if (movement.IsInPits && result.CurrentLap != null) { result.CurrentLap.WasOnPitRoad = true; } result.Stint = (result.CurrentLap?.Number ?? 0) - (result.CurrentPitStop?.LapNumber ?? 0); if (!result.PitLaneEntryTime.HasValue) { if (movement.IsInPits) { result.PitLaneEntryTime = now; var stop = new PitStop { LapNumber = result.CurrentLap.Number }; result.PitStopsInt.Add(stop); result.CurrentPitStop = stop; var ev = new SessionEvent(result.CurrentLap.ReplayPosition, "Pit Stop on Lap " + result.CurrentLap.Number, result.Entity, sim.CameraManager.CurrentGroup, session.Type, SessionEventType.Pit, result.CurrentLap.Number); lock (sim.SharedCollectionLock) { ((Session.Session)sim.Session).SessionEventsInt.Add(ev); } sim.Triggers.Push(new TriggerInfo { CarIdx = result.Entity.CarIdx, Type = EventType.PitIn }); } } else { var stop = result.CurrentPitStop as PitStop; stop.PitLaneTime = now - result.PitLaneEntryTime.Value; if (!result.PitStopStartTime.HasValue) { if (inPitStall && Math.Abs(movement.Speed) <= 0.1F) { result.PitStopStartTime = now; stop.PitStopTime = 0; } } else { stop.PitStopTime = now - result.PitStopStartTime.Value; if (!inPitStall) { if (result.PitStopEndTime.HasValue && Math.Abs(result.PitStopEndTime.Value - now) < 10E-1) { continue; } if (!result.HasIncrementedCounter) { result.PitStopCount++; result.HasIncrementedCounter = true; } stop.LapNumber = result.CurrentLap.Number; result.PitStopStartTime = null; result.PitStopEndTime = now; } } if (!movement.IsInPits) { result.PitLaneExitTime = now; result.HasIncrementedCounter = false; stop.PitLaneTime = result.PitLaneExitTime.Value - result.PitLaneEntryTime.Value; result.PitLaneEntryTime = null; sim.Triggers.Push(new TriggerInfo { CarIdx = result.Entity.CarIdx, Type = EventType.PitOut }); } } } }
// GET: PitStop/Details/5 public ActionResult Details(int id) { PitStop pitstop1 = rep.GetPitStop(id); return(View()); }