public async Task <IActionResult> AddTripAsync([FromBody] TripDTO model) { try { if (model == null) { logger.LogError($"Object sent from client is null"); return(BadRequest("Trip object is null")); } if (!ModelState.IsValid) { logger.LogError($"Object state is not valid"); return(BadRequest("Trip object is invalid")); } var trip = new Trip { Name = model.Name, IsDone = model.IsDone, Description = model.Description }; var userId = caller.Claims.Single(c => c.Type == "id"); var user = await unitOfWork.Users.GetUserByIdentityId(userId.Value); trip.UserInfo = user; unitOfWork.Trips.Add(trip); model.UserId = user.Id; return(Ok(model)); } catch (Exception ex) { logger.LogError($"Error occured inside AddTripAsync:{ex.Message}"); return(StatusCode(500, "Internal server error")); } }
public async void GetTripsByLineID_Exists() { var repo = new Mock <ITripRepository> (); var uow = new Mock <IUnitOfWork> (); string lineID = "Line:1"; string pathID = "Path:1"; string tripDepartureTime = "20:12:10"; LineId line = new LineId(lineID); var trip = new Trip(lineID, pathID, tripDepartureTime); var trips = new List <Trip> () { trip }; var tripDTO = new TripDTO(trip.Id.AsGuid(), new LineId(lineID), new PathId(pathID), tripDepartureTime); var tripsDTO = new List <TripDTO> () { tripDTO }; repo.Setup(_ => _.GetTripsByLineID(line)).ReturnsAsync(trips); var service = new TripService(repo.Object, uow.Object); var actual = await service.GetTripsByLineID(line); Assert.Equal(tripsDTO, actual); }
public async void GetByLineId() { var tripServiceMock = new Mock <ITripService> (); var pathServiceMock = new Mock <IPathService> (); string lineID = "Line:1"; string pathID = "Path:1"; string tripDepartureTime = "20:12:10"; var trip = new Trip(lineID, pathID, tripDepartureTime); var tripDTO = new TripDTO(trip.Id.AsGuid(), new LineId(lineID), new PathId(pathID), tripDepartureTime); var tripsDTO = new List <TripDTO> () { tripDTO }; var line = new LineId(lineID); tripServiceMock.Setup(_ => _.GetTripsByLineID(line)).ReturnsAsync(tripsDTO); var controller = new TripController(tripServiceMock.Object, pathServiceMock.Object); var actual = await controller.GetByLineId(lineID); Assert.Equal(tripsDTO, actual.Value); }
public async Task AddTrip(TripDTO tripDto) { if (!await IsValidRoute(tripDto.RouteId)) { throw await _serviceHelper.GetExceptionAsync(ErrorConstants.ROUTE_NOT_EXIST); } if (!await IsValidVehicleModel(tripDto.VehicleModelId.GetValueOrDefault())) { throw await _serviceHelper.GetExceptionAsync(ErrorConstants.VEHICLE_MODEL_NOT_EXIST); } _tripRepo.Insert(new Trip { DepartureTime = tripDto.DepartureTime, TripCode = tripDto.Code, RouteId = tripDto.RouteId, ParentRouteId = tripDto.ParentRouteId, ParentRouteDepartureTime = tripDto.ParentDepartureTime, ParentTripId = tripDto.ParentTripId, VehicleModelId = tripDto.VehicleModelId, AvailableOnline = tripDto.AvailableOnline }); await _unitOfWork.SaveChangesAsync(); }
private async void EditButton_Click(object sender, RoutedEventArgs e) { TripNameTextBox.Text = _trip.Name; TripStartDatePicker.Date = new DateTimeOffset((DateTime)_trip.StartDateTime); TripEndDatePicker.Date = new DateTimeOffset((DateTime)_trip.EndDateTime); if (await EditTripDialog.ShowAsync() != ContentDialogResult.Primary) { return; } var editedTrip = new TripDTO { Name = TripNameTextBox.Text, StartDateTime = TripStartDatePicker.Date.DateTime, EndDateTime = TripEndDatePicker.Date.DateTime }; try { _trip = await _service.UpdateTrip(_trip.Id, editedTrip); _navigationView.Header = _trip.Name; Bindings.Update(); } catch { //TODO: Exception handling } }
public HttpResponseMessage Put(int id, [FromBody] TripDTO trip) { Reservation reservation = Reservations.FindBy(r => r.DepartFlightScheduleID == id || r.ReturnFlightScheduleID == id).FirstOrDefault(); if (reservation == null) { return(Request.CreateResponse(HttpStatusCode.NotFound)); } Trip orignalEntity; if (reservation.DepartFlightScheduleID == id) { orignalEntity = reservation.DepartureFlight; } else { orignalEntity = reservation.ReturnFlight; } Reservations.UpdateTrip(orignalEntity, trip.FromTripDTO()); Reservations.Save(); return(Request.CreateResponse(HttpStatusCode.OK)); }
public async void Create() { var tripServiceMock = new Mock <ITripService> (); var pathServiceMock = new Mock <IPathService> (); string lineID = "Line:1"; string pathID = "Path:1"; string tripDepartureTime = "20:12:10"; var trip = new Trip(lineID, pathID, tripDepartureTime); var tripDTO = new TripDTO(trip.Id.AsGuid(), new LineId(lineID), new PathId(pathID), tripDepartureTime); var path = new PathId(pathID); var pathDTO = new PathDTO(pathID, true, new List <SegmentDTO> ()); var creatingTrip = new CreatingTripDTO(lineID, pathID, tripDepartureTime); pathServiceMock.Setup(_ => _.GetById(path)).ReturnsAsync(pathDTO); tripServiceMock.Setup(_ => _.AddTrip(creatingTrip, new List <CreatingNodePassageDTO> ())).ReturnsAsync(tripDTO); var controller = new TripController(tripServiceMock.Object, pathServiceMock.Object); var actual = await controller.Create(creatingTrip); Assert.NotNull(actual); Assert.NotNull(actual.Result); }
public async Task UpdateTrip(Guid tripId, TripDTO tripDto) { var trip = await _tripRepo.GetAsync(tripId); if (trip is null) { throw await _serviceHelper.GetExceptionAsync(ErrorConstants.TRIP_NOT_EXIST); } if (!await IsValidVehicleModel(tripDto.VehicleModelId.GetValueOrDefault())) { throw await _serviceHelper.GetExceptionAsync(ErrorConstants.VEHICLE_MODEL_NOT_EXIST); } trip.DepartureTime = tripDto.DepartureTime; trip.ParentTripId = tripDto.ParentTripId; trip.TripCode = tripDto.Code; trip.RouteId = tripDto.RouteId; trip.ParentRouteId = tripDto.ParentRouteId; trip.VehicleModelId = tripDto.VehicleModelId; trip.AvailableOnline = tripDto.AvailableOnline; trip.ParentRouteDepartureTime = tripDto.ParentDepartureTime; await _unitOfWork.SaveChangesAsync(); }
public async Task can_add_trip() { TripDTO trip3 = new TripDTO() { VehicleId = 1, Date = DateTime.Now.Date, Odometer = 1578, TripMeter = 150.9m, TotalGallons = 10.58m, TotalFuelCost = 23.21m }; // The endpoint or route of the controller action. var httpResponse = await _client.PostAsync("/api/trips", getBodyJson(trip3)); // Must be successful. httpResponse.EnsureSuccessStatusCode(); var stringResponse = await httpResponse.Content.ReadAsStringAsync(); var trip = JsonConvert.DeserializeObject <TripDTO>(stringResponse); Assert.True(trip.Odometer > 0); Assert.True(trip.Id > 0); }
public string TripGetAllByNoOfDays(string nod) { var noOfDays = -1; try { noOfDays = Convert.ToInt32(nod); } catch { } var listTrip = AddSeriesBookingsBLL.TripGetAllByNoOfDays(noOfDays); var listTripDTO = new List <TripDTO>(); foreach (var trip in listTrip) { var tripDTO = new TripDTO() { Id = trip.Id, Name = trip.Name }; listTripDTO.Add(tripDTO); } Dispose(); return(JsonConvert.SerializeObject(listTripDTO)); }
public async Task <ActionResult <TripDTO> > PostTrip(TripDTO tripDTO) { var trip = new Trip() { CompanyId = tripDTO.CompanyId, Departure = tripDTO.Departure, Recurrence = tripDTO.Recurrence, Recipient = tripDTO.Recipient, Purpose = tripDTO.Purpose, DistanceInKM = tripDTO.DistanceInKM, LocationDeparture = tripDTO.LocationDeparture, LocationDestination = tripDTO.LocationDestination, Description = tripDTO.Description, PassengerCount = tripDTO.PassengerCount }; _context.Trips.Add(trip); await _context.SaveChangesAsync(); return(CreatedAtAction( nameof(GetTrip), new { id = trip.Id }, TripToDTO(trip) )); }
public WorkBlockAux(int pos, int sum, TripDTO trip) { this.pos = pos; this.sum = sum; this.tripList = new List <TripDTO>(); this.tripList.Add(trip); }
public async Task <TripDTO> AddMemberToTrip(int tripId, int memberId, bool IsTeam) { using (_unitOfWork) { Trip trip = await _unitOfWork.TripRepository.GetTripWithItemsAndMembers(tripId); Member member; if (IsTeam) { member = await _unitOfWork.TeamRepository.GetTeamWithMembers(memberId); } else { member = await _unitOfWork.UserRepository.FindByID(memberId); } if (trip.Travelers == null) { trip.Travelers = new List <User>(); } foreach (User user in member.GetUsers()) { if (!trip.Travelers.Contains(user)) { trip.Travelers.Add(user); if (user.MyTrips == null) { user.MyTrips = new List <Trip>(); } user.MyTrips.Add(trip); _unitOfWork.UserRepository.Update(user); Notification notification = new Notification() { Seen = false, RelatedObjectName = trip.Name, Type = NotificationType.NewTrip, User = user, UserId = user.UserId }; await _unitOfWork.NotificationRepository.Create(notification); NotificationTripDTO notificationTrip = new NotificationTripDTO() { Notification = _mapper.Map <Notification, NotificationDTO>(notification), Trip = _mapper.Map <Trip, TripDTO>(trip) }; await _messageControllerService.SendNotification(user.UserId, "AddToTripNotification", notificationTrip); } } _unitOfWork.TripRepository.Update(trip); await _unitOfWork.Save(); await _messageControllerService.NotifyOnTripChanges(trip.TripId, "AddMemberToTrip", member.GetUsers().Select(user => _mapper.Map <User, UserBasicDTO>(user))); TripDTO retTrip = _mapper.Map <Trip, TripDTO>(trip); return(retTrip); } }
public HttpResponseMessage Put(int id, [FromBody] TripDTO trip) { Reservation reservation = Reservations.FindBy(r => r.DepartFlightScheduleID == id || r.ReturnFlightScheduleID == id).FirstOrDefault(); if (reservation == null) { return(Request.CreateResponse(HttpStatusCode.NotFound)); } Trip orignalEntity; FlightDirections flightDirection; if (reservation.DepartFlightScheduleID == id) { orignalEntity = reservation.DepartureFlight; flightDirection = FlightDirections.Departing; } else { orignalEntity = reservation.ReturnFlight; flightDirection = FlightDirections.Returning; } Reservations.UpdateTrip(orignalEntity, trip.FromTripDTO()); Reservations.Save(); // send a reservation update request to the backend booking service UpdateReservationOnBackendSystem(reservation, orignalEntity, flightDirection); return(Request.CreateResponse(HttpStatusCode.OK)); }
// GET: CarRentals/Details/5 public async Task <IActionResult> Details(int?id) { if (id == null) { return(NotFound()); } var carRental = await _context.CarRentals .SingleOrDefaultAsync(m => m.Id == id); TripDTO _tDto = new TripDTO(); MyCarRentals _cr = new MyCarRentals(); DatabaseManager.FlightId = 0; DatabaseManager.LodgingId = 0; DatabaseManager.OtherTransportationId = 0; DatabaseManager.RestaurantId = 0; DatabaseManager.CarRentalId = (int)id; DatabaseManager.ActivityTaskId = 0; _cr.Id = DatabaseManager.CarRentalId; _cr.SuppplierName = carRental.SuppplierName; _cr.ConfirmationNumber = carRental.ConfirmationNumber; _cr.PickupName = carRental.PickupName; _cr.PickupAddress = carRental.PickupAddress; _cr.PickupSuburb = carRental.PickupSuburb; _cr.PickupCity = carRental.PickupCity; _cr.PickupRegion = carRental.PickupRegion; _cr.PickupPostcode = carRental.PickupPostcode; _cr.PickupCountry = carRental.PickupCountry; _cr.PickupDate = carRental.PickupDate; _cr.PickupTime = carRental.PickupTime; _cr.DropoffAddress = carRental.DropoffAddress; _cr.DropoffSuburb = carRental.DropoffSuburb; _cr.DropoffCity = carRental.DropoffCity; _cr.DropoffRegion = carRental.DropoffRegion; _cr.DropoffPostcode = carRental.DropoffPostcode; _cr.DropoffCountry = carRental.DropoffCountry; _cr.DropoffDate = carRental.DropoffDate; _cr.DropoffTime = carRental.DropoffTime; _cr.SupplierPhoneNumber = carRental.SupplierPhoneNumber; _cr.TripId = carRental.TripId; _cr.DropoffCheckbox = carRental.DropoffCheckbox; _cr.Door = carRental.Door; _cr.Seats = carRental.Seats; _cr.Transmission = carRental.Transmission; _cr.LargeBag = carRental.LargeBag; _cr.SmallBag = carRental.SmallBag; _cr.Litres = carRental.Litres; _tDto.AllHumans = _context.Humans.ToList(); if (carRental == null) { return(NotFound()); } _tDto.MyCarRental = _cr; return(View(_tDto)); }
public async Task <ServiceResponse <bool> > AddTrip(TripDTO trip) { return(await HandleApiOperationAsync(async() => { await _tripService.AddTrip(trip); return new ServiceResponse <bool>(true); })); }
public async Task <ServiceResponse <bool> > UpdateTrip(Guid id, TripDTO trip) { return(await HandleApiOperationAsync(async() => { await _tripService.UpdateTrip(id, trip); return new ServiceResponse <bool>(true); })); }
public async void GetById() { var service = new Mock <IDriverDutyService>(); string driverDutyCode = "dDutycode1"; var tripList = new List <Trip>(); string lineID = "Line:1"; string pathID = "Path:1"; string tripDepartureTime = "20:12:10"; var trip = new Trip(lineID, pathID, tripDepartureTime); tripList.Add(trip); var workBlock1 = new WorkBlock("9:0:0", "10:0:0", tripList); var workBlock2 = new WorkBlock("10:0:0", "13:0:0", tripList); var workBlock3 = new WorkBlock("14:0:0", "18:0:0", tripList); var workBlockList = new List <WorkBlock> { workBlock1, workBlock2, workBlock3 }; var driverDuty = new DriverDuty(driverDutyCode, workBlockList); var tripDTO = new TripDTO(trip.Id.AsGuid(), new LineId(lineID), new PathId(pathID), tripDepartureTime); var tripsDTO = new List <TripDTO>() { tripDTO }; var listWorkBlocksString = new List <String>() { workBlock1.Id.Value, workBlock2.Id.Value, workBlock3.Id.Value }; var workBlockDTO1 = new WorkBlockDTO(workBlock1.Id.AsGuid(), workBlock1.startingTime.time, workBlock1.endingTime.time, tripsDTO); var workBlockDTO2 = new WorkBlockDTO(workBlock2.Id.AsGuid(), workBlock2.startingTime.time, workBlock2.endingTime.time, tripsDTO); var workBlockDTO3 = new WorkBlockDTO(workBlock3.Id.AsGuid(), workBlock3.startingTime.time, workBlock3.endingTime.time, tripsDTO); var listWorkBlockDTO = new List <WorkBlockDTO>() { workBlockDTO1, workBlockDTO2, workBlockDTO3 }; var driverDutyDTO = new DriverDutyDTO(driverDuty.Id.AsGuid(), driverDutyCode, listWorkBlockDTO); service.Setup(_ => _.GetById(driverDuty.Id)).ReturnsAsync(driverDutyDTO); var controller = new DriverDutyController(service.Object); var actual = await controller.GetById(driverDuty.Id.AsGuid()); Assert.Equal(driverDutyDTO, actual.Value); }
public void Put(int id, [FromBody] TripDTO value) { var claims = User.Claims; if (value.UserTripDTO.First().UserName == User.Identity.Name || User.HasClaim("IsAdmin", "true")) { _service.UpdateTrip(value); } }
public void DTOtoDomain() { var mapper = new DriverDutyMapper(); string driverDutyCode = "dDutycode1"; var tripList = new List <Trip>(); string lineID = "Line:1"; string pathID = "Path:1"; string tripDepartureTime = "20:12:10"; var trip = new Trip(lineID, pathID, tripDepartureTime); tripList.Add(trip); var workBlock1 = new WorkBlock("9:0:0", "10:0:0", tripList); var workBlock2 = new WorkBlock("10:0:0", "13:0:0", tripList); var workBlock3 = new WorkBlock("14:0:0", "18:0:0", tripList); var workBlockList = new List <WorkBlock> { workBlock1, workBlock2, workBlock3 }; var tripDTO = new TripDTO(trip.Id.AsGuid(), new LineId(lineID), new PathId(pathID), tripDepartureTime); var tripsDTO = new List <TripDTO>() { tripDTO }; var listWorkBlocksString = new List <String>() { workBlock1.Id.Value, workBlock2.Id.Value, workBlock3.Id.Value }; var workBlockDTO1 = new WorkBlockDTO(workBlock1.Id.AsGuid(), workBlock1.startingTime.time, workBlock1.endingTime.time, tripsDTO); var workBlockDTO2 = new WorkBlockDTO(workBlock2.Id.AsGuid(), workBlock2.startingTime.time, workBlock2.endingTime.time, tripsDTO); var workBlockDTO3 = new WorkBlockDTO(workBlock3.Id.AsGuid(), workBlock3.startingTime.time, workBlock3.endingTime.time, tripsDTO); var listWorkBlockDTO = new List <WorkBlockDTO>() { workBlockDTO1, workBlockDTO2, workBlockDTO3 }; var driverDuty = new DriverDuty(driverDutyCode, workBlockList); var expected = new DriverDutyDTO( driverDuty.Id.AsGuid(), driverDutyCode, listWorkBlockDTO ); var actual = mapper.DomainToDTO(driverDuty); Assert.Equal(actual, expected); }
public async Task <Guid> AddTripAsync(TripDTO tripDto) { var id = Guid.NewGuid(); await _tripRepository.AddTripAsync(new Trip(id, tripDto.Name, tripDto.Destination, tripDto.StartDate, tripDto.EndDate, _dateTimeOffsetProvider)); return(id); }
public async Task <bool> DeleteTrip(TripDTO tripModel) { if (tripModel != null && await _tripRepo.DeleteTrip(tripModel.Id)) { return(true); } return(false); }
public Trip(TripDTO tripDTO, IdentityUser user) { Destination = tripDTO.Destination; DepartureDate = tripDTO.DepartureDate; ReturnDate = tripDTO.ReturnDate; User = user; TripItems = new List <TripItem>(); TripTasks = new List <TripTask>(); ItineraryItems = new List <ItineraryItem>(); }
public async void ShouldAddTrip() { //Given var now = DateTime.Now; var companyName = "New One"; var calendar = await CalendarRepository.Add(now); var company = await CompanyRepository.Add(new Company { Name = companyName }, true); var vehicle = await VehicleRepository.Add(new Vehicle { Name = "Vehicle" }, true); var vehicleType = await VehicleTypeRepository.Add(new VehicleType { Name = "VehicleType" }, true); var neighborhood = await NeighborhoodRepository.Add(new Neighborhood { Name = "Neighborhood" }, true); var patternArea = await PatternAreaRepository.Add(new PatternArea { Name = "Pattern Area" }, true); var paymentType = await PaymentTypeRepository.Add(new PaymentType { Name = "Payment" }, true); var controller = new TripController( new Mock <ILogger <TripController> >().Object, TripRepository, CalendarRepository, CompanyRepository, VehicleRepository ); var tripDTO = new TripDTO { StartTime = now, EndTime = now.AddHours(2), CompanyName = companyName, VehicleName = vehicle.Name, VehicleTypeKey = Convert.ToByte(vehicleType.Key), NeighborhoodStartKey = neighborhood.Key, NeighborhoodEndKey = neighborhood.Key, PatternAreaStartKey = patternArea.Key, PatternAreaEndKey = patternArea.Key, PaymentTypeKey = Convert.ToByte(paymentType.Key), PaymentAccessKey = Convert.ToByte(paymentType.Key) }; //When var result = await controller.PostAsync(tripDTO); var dbTrip = await TripRepository.Find(1); //Then var viewResult = Assert.IsType <OkObjectResult>(result); var model = Assert.IsType <TripDTO>(viewResult.Value); Assert.NotNull(model); Assert.Equal(tripDTO.EndTime.TimeOfDay, dbTrip.EndTime); }
public IActionResult AddTrip(TripDTO t) { Trip trip = new Trip() { Name = t.Name, Date = t.Date }; getLoggedUser().AddTrip(trip); _userRepository.SaveChanges(); return(NoContent()); }
public IActionResult Put(int id, [FromBody] TripDTO trip) { var fromDto = _mapper.Map <TripDTO, Trip>(trip); var updated = _uow.GetRepository <Trip>().Update(fromDto); _uow.SaveChanges(); var dto = _mapper.Map <Trip, TripDTO>(updated); return(Ok(dto)); }
public IActionResult Post([FromBody] TripDTO trip) { var fromDto = _mapper.Map <TripDTO, Trip>(trip); var added = _uow.GetRepository <Trip>().Add(fromDto); _uow.SaveChanges(); var dto = _mapper.Map <Trip, TripDTO>(added); return(Ok(dto)); }
public async Task <TripDTO> CreateTrip(TripDTO tripModel) { Trip trip = TripMapper.ConvertModelToEntity(tripModel); if (await _tripRepo.CreateTrip(trip)) { return(TripMapper.ConvertEntityToModel(trip)); } return(null); }
public ActionResult <Trip> AddTrip(TripDTO dto) { Trip t = new Trip() { Name = dto.Name, Date = dto.Date }; _tripRepository.AddTrip(t); _tripRepository.SaveChanges(); return(t); }
public async Task EditTripAsync(Guid tripId, TripDTO tripDto) { if (tripDto == null) { throw new DomainException(DomainErrorCodes.ArgumentNullOrEmpty, null, "Trip is null!"); } var trip = await _tripRepository.GetTripAsync(tripId); CheckTripNullOrFail(trip); trip.Edit(tripDto.Name, tripDto.Destination, tripDto.TripStatus, tripDto.StartDate, tripDto.EndDate); await _tripRepository.UpdateTripAsync(trip); }