public async Task <IActionResult> Edit(int id, [Bind("Id,UserId,Name,Tractor,Epj,Date,Trailer,RouteNumber,LoadQualitySurvey,TurnInBols,TurnInAllPaperwork,PalletJack,ReturnMisPicks,ClearTrailer,SweepTrailer,ReportTrailer,RetunDvir,ReportEquipmentDamages,StrapsHanding,TrailerShuttle,TrailerLocation,DriverSignature")] EndRouteCheck endRouteCheck) { if (id != endRouteCheck.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(endRouteCheck); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!EndRouteCheckExists(endRouteCheck.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(endRouteCheck)); }
public async Task <IActionResult> Create([Bind("Id,UserId,Name,Tractor,Epj,Date,Trailer,RouteNumber,LoadQualitySurvey,TurnInBols,TurnInAllPaperwork,PalletJack,ReturnMisPicks,ClearTrailer,SweepTrailer,ReportTrailer,RetunDvir,ReportEquipmentDamages,StrapsHanding,TrailerShuttle,TrailerLocation,DriverSignature")] EndRouteCheck endRouteCheck) { if (ModelState.IsValid) { //Grabbing logged in users id string userId = _userManager.GetUserId(HttpContext.User); //Adding logged in users trip information ApplicationUser user = _context.Users.Where(a => a.Id == userId).FirstOrDefault(); //Assigning trip user ID to the logged in users ID so we can keep track of all trips created endRouteCheck.UserId = user.Id; //This variable lets us access most recent Trip properties var mostRecentTrip = _context.Trip.Where(t => t.UserId == userId).OrderByDescending(x => x.StartTime).FirstOrDefault(); if (mostRecentTrip == null) { return(View()); } //This variable lets us access most recent OperatorEquipment properties var mostRecentEpj = _context.OperatorEquipment.Where(e => e.UserId == userId).OrderByDescending(z => z.Date).FirstOrDefault(); if (mostRecentEpj == null) { return(View()); } //Assigning tractor number that was used on the most recent trip endRouteCheck.Tractor = mostRecentTrip.Tractor; //Assigning trailer number that was used on most recent trip endRouteCheck.Trailer = mostRecentTrip.Trailer; //Assigning routenumber that was used on the most recent trip endRouteCheck.RouteNumber = mostRecentTrip.RouteNumber; //Assigning Electric Pallet Jack(EPJ) number endRouteCheck.Epj = mostRecentEpj.Epj; //Assigning the name of the logged in user to the trip full name field endRouteCheck.Name = user.FirstName + " " + user.LastName; _context.Add(endRouteCheck); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(endRouteCheck)); }