public async Task <TripVM> getAtrip(int id) { Trip dbTrip = await _db.Trips.FindAsync(id); if (dbTrip == null) { return(null); } else { var utTrip = new TripVM() { id = dbTrip.TripID, tripDate = dbTrip.TripDate, StringTripDate = dbTrip.TripDate.ToString("MM/dd/yyyy"), tripTime = dbTrip.TripTime, StringTripTime = dbTrip.TripTime.ToString("MM/dd/yyyy"), departure = dbTrip.DepartureStation.StationName, arrival = dbTrip.ArrivalStation.StationName, adultPrice = dbTrip.AdultPrice, studentPrice = dbTrip.StudentPrice, childPrice = dbTrip.ChildPrice, seniorPrice = dbTrip.SeniorPrice }; return(utTrip); } }
public async Task <bool> update(TripVM innTrip) { Trip endreTrip = _db.Trips.Find(innTrip.id); endreTrip.TripDate = innTrip.tripDate; endreTrip.TripTime = innTrip.tripTime; endreTrip.Departure = innTrip.departure; endreTrip.Arrival = innTrip.arrival; endreTrip.AdultPrice = innTrip.adultPrice; endreTrip.StudentPrice = innTrip.studentPrice; endreTrip.ChildPrice = innTrip.childPrice; endreTrip.SeniorPrice = innTrip.seniorPrice; try { //Deperture Condition var eksistererdepartureStation = _db.Stations.FirstOrDefault(s => s.StationName == innTrip.departure); if (eksistererdepartureStation == null) { var nyttDeparureStation = new Station() { StationName = innTrip.departure }; endreTrip.DepartureStation = nyttDeparureStation; } else { //setting the eksising station id in This new Trip record endreTrip.DepartureStation = eksistererdepartureStation; } //Arrival Condition var eksistererArrivalStation = _db.Stations.FirstOrDefault(s => s.StationName == innTrip.arrival); if (eksistererArrivalStation == null) { var nyttArrivalStation = new Station() { StationName = innTrip.arrival }; endreTrip.ArrivalStation = nyttArrivalStation; } else { //setting the eksising station id in This new Trip record endreTrip.ArrivalStation = eksistererArrivalStation; } //update a Trip await _db.SaveChangesAsync(); return(true); } catch (IOException e) { if (e.Source != null) { Console.WriteLine("IOException source: {0}", e.Source); } throw; } }
public async Task <ActionResult> GetAtrip(int id) { if (string.IsNullOrEmpty(HttpContext.Session.GetString(_loggetInn))) { return(Unauthorized("Ikke logget inn")); } TripVM turen = await _db.getAtrip(id); if (turen == null) { _log.LogInformation("Fant ikke kunden"); return(NotFound("Fant ikke kunden")); } return(Ok(turen)); }
public BaseResult MergeTrip(TripVM tripVM, IEnumerable <DriverInfoVM> drivers) { var result = new BaseResult(); try { var trip = Mapper.Map <Trip>(tripVM); if (tripVM.Id == 0) { trip.CreatedBy = AccountId; } trip.ModifiedBy = AccountId; var schedule = UnitOfWork.ScheduleDao.FindById(trip.ScheduleId); var firstRouteLocation = UnitOfWork.StoredProcedureDao.GetRouteLocation(schedule.RouteId).FirstOrDefault(); UnitOfWork.TripDao.Merge(trip); var tripBus = new TripBus { BusId = tripVM.BusId, TripId = trip.Id, LocationId = firstRouteLocation.CurrentLocationId.Value, CreatedBy = AccountId, ModifiedBy = AccountId }; UnitOfWork.TripBusDao.Merge(tripBus); foreach (var driver in drivers) { var tripBusDriver = new TripBusDriver { DriverId = driver.DriverId.Value, TripBusId = tripBus.Id, CreatedBy = AccountId, ModifiedBy = AccountId }; UnitOfWork.TripBusDriverDao.Merge(tripBusDriver); } result.Success = true; result.Message = GeneralSuccessMessage; } catch (Exception ex) { result.Success = false; result.Message = GeneralErrorMessage; } return(result); }
public IActionResult TripDetails(int id) { TripVM trip = _context.Trips.Include(a => a.Passenger).Include(b => b.Driver).Include(c => c.Payment).Select(q => new TripVM() { ID = q.ID, ArrivalPoint = q.ArrivalPoint, DeparturePoint = q.DeparturePoint, PassengerName = q.Passenger.Name, PassengerLastname = q.Passenger.Surname, DriverName = q.Driver.Name, DriverLastname = q.Driver.Surname, Price = q.Payment.Price }).FirstOrDefault(x => x.ID == id); return(View(trip)); }
public async Task <ActionResult> Edit(TripVM tripVM) { if (string.IsNullOrEmpty(HttpContext.Session.GetString(_loggetInn))) { return(Unauthorized("Ikke logget inn")); } if (ModelState.IsValid) { bool returOK = await _db.update(tripVM); if (!returOK) { _log.LogInformation("Endringen kunne ikke utføres"); return(NotFound("Endringen av turen kunne ikke utføres")); } return(Ok("turen endret")); } _log.LogInformation("Feil i inputvalidering"); return(BadRequest("Feil i inputvalidering på server")); }
public async Task <ActionResult> Save(TripVM tripVM) { if (string.IsNullOrEmpty(HttpContext.Session.GetString(_loggetInn))) { return(Unauthorized("Ikke logget inn")); } if (ModelState.IsValid) { bool returOK = await _db.settInn(tripVM); if (!returOK) { _log.LogInformation("Turen kunne ikke lagres!"); return(BadRequest("Turen kunne ikke lagres")); } return(Ok("turen lagret")); } _log.LogInformation("Feil i inputvalidering"); return(BadRequest("Feil i inputvalidering på server")); }
public IActionResult MergeTrip(TripVM trip, IEnumerable <int> drivers) { var result = new Result(); try { var oldTrip = ServiceFactory.TripManagement.GetTrip(trip?.Id).Data; trip.Status = oldTrip?.Status ?? TripStatus.P.ToString(); var mergeTripResult = ServiceFactory.TripManagement.MergeTrip(trip, drivers.Select(x => new DriverInfoVM { DriverId = x })); result.Success = mergeTripResult.Success; result.Message = mergeTripResult.Message; } catch (Exception) { result.Success = false; } return(Json(result)); }
public async Task <bool> Save(TripVM tripVM) { return(await _db.settInn(tripVM)); }