protected override void OnNavigatedTo(NavigationEventArgs e) { var grid = (Grid)e.Parameter; CurrentTrip = (TripDto)grid.DataContext; contentFrame.Navigate(typeof(TripDetails), CurrentTrip); }
public void AddBooking(string client, string phone, int numTickets, Trip trip, Account account) { LOGGER.InfoFormat("adding booking for client {0} fo trip {1} tickets {2}", client, trip, numTickets); EnsureConnected(); TripDto t = new TripDto(trip.Id, trip.Landmark, trip.CompanyName, trip.DepartureTime, trip.Price, trip.AvailablePlaces); AccountDto a = new AccountDto(account.Id, account.Name, account.Password); Request r = new Request() { Type = RequestType.ADD_BOOKING, Data = new BookingDto(client, phone, numTickets, t, a) }; SendRequest(r); Response response = ReadResponse(); LOGGER.InfoFormat("response for add booking {0}", response); if (response.Type == ResponseType.OK) { LOGGER.Info("booking added"); return; } if (response.Type == ResponseType.ERROR) { String err = response.Data.ToString(); LOGGER.Info("received ERROR response " + err); throw new ServiceException(err); } }
private static void AssertTripsAreEqual(Trip expected, TripDto actual) { Assert.NotNull(expected); Assert.NotNull(actual); Assert.Equal(expected.Id, actual.Id); Assert.Equal(expected.Description, actual.Description); }
public async Task <int> InsertTripAsync(TripDto trip) { using (var sqlConn = new SqlConnection(_configuration.GetConnectionString("DefaultConnection"))) { return((await sqlConn.QueryAsync <int>("[dbo].[usp_Trip_Insert]", new { trip.TravelerId, trip.DepartureDate, trip.ReturnDate }, commandType: CommandType.StoredProcedure).ConfigureAwait(false)).FirstOrDefault()); } }
public async Task UpdateAsync_ValidData_Successful() { // Arrange. Seed(TripFlipDbContext, UserEntityToSeed); Seed(TripFlipDbContext, TripEntityToSeed); Seed(TripFlipDbContext, TripSubscriberEntityToSeed); Seed(TripFlipDbContext, TripSubscriberAdminRoleEntityToSeed); CurrentUserService = CreateCurrentUserServiceWithExistentUser(); TripService = new TripService(TripFlipDbContext, Mapper, CurrentUserService); var updateTripDto = GetUpdateTripDto(); // Act. var resultTripDto = await TripService.UpdateAsync(updateTripDto); var expectedTripDto = new TripDto() { Id = updateTripDto.Id, Title = updateTripDto.Title, Description = updateTripDto.Description, StartsAt = updateTripDto.StartsAt, EndsAt = updateTripDto.EndsAt }; var tripDtoComparer = new TripDtoComparer(); // Assert. Assert.AreEqual(0, tripDtoComparer.Compare(expectedTripDto, resultTripDto)); }
public async Task <IActionResult> PostTripById([FromBody] TripDto tripDto) { string getUserId = User.FindFirst(ClaimTypes.NameIdentifier)?.Value; var currentUser = await _userManager.FindByIdAsync(getUserId); Trip trip = new Trip() { Customer = currentUser, CreatedAt = tripDto.CreatedAt, Status = tripDto.Status, EstimatedTime = tripDto.EstimatedTime, Distance = tripDto.Distance, Price = tripDto.Price ?? 0, StartLocation = tripDto.StartLocation, EndLocation = tripDto.EndLocation, Contractor = tripDto.Contractor }; await _dbContext.Trips.AddAsync(trip); await _dbContext.SaveChangesAsync(); return(Ok(new Response { Status = "Success", Message = "Trip created successfully." })); }
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! // // You wouldn't actually have to write any of this code. Automapper does it _for_ you by reflection/convention. // // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! public static IViewModel MapToViewModel(TripDto trip) { var t1 = trip as CreditCardTripDto; if (t1 != null) { return(new CreditCardViewModel { CreditCardNumber = t1.CreditCardNumber, CardSecurityCode = t1.CardSecurityCode, ExpirationDate = t1.ExpirationDate }); } var t2 = trip as InternalCardTripDto; if (t2 != null) { return(new InternalCardViewModel { InternalCardNumber = t2.InternalCardNumber }); } var t3 = trip as RequisitionTripDto; return(new RequisitionViewModel { RequisitionNumber = t3.RequisitionNumber }); }
private void PublishNonPersistent(ref string inputString) { Console.WriteLine(); var message = new TripDto { Car = "Performance" }; int.TryParse(inputString, out var count); Console.WriteLine($"Publish Non-Persistent {count} times"); try { var stopwatch = new Stopwatch(); stopwatch.Start(); for (var i = 0; i < count; ++i) { _messageBus.Publish(SampleApiConfiguration.TripCreated, message); } stopwatch.Stop(); Console.WriteLine($"Publish Non-Persistent - Count: {count} - Total: {(double)stopwatch.ElapsedMilliseconds / 1000:#0.###}s - Average: {stopwatch.ElapsedMilliseconds / count}ms"); } catch (Exception exception) { Console.WriteLine("Exception publish: " + exception.SerializeToJson()); } inputString = ""; }
public async Task <BaseResult> UpdateAsync(TripDto tripDto) { if (tripDto == null) { throw new ArgumentNullException(nameof(tripDto)); } if (tripDto.FromCityId == null) { throw new ArgumentNullException(nameof(tripDto.FromCityId)); } if (tripDto.ToCountryId == null) { throw new ArgumentNullException(nameof(tripDto.ToCountryId)); } var trip = new Trip { Id = tripDto.Id, DateTo = tripDto.DateTo, DateFrom = tripDto.DateFrom, PreferredGender = tripDto.PreferredGender, Comment = tripDto.Comment, FromCityId = tripDto.FromCityId.Value, ToCityId = tripDto.ToCityId, ToCountryId = tripDto.ToCountryId.Value, UserId = tripDto.UserId }; return(await _tripStorage.UpdateAsync(trip)); }
public async Task <BaseResult> CreateAsync(TripDto tripDto) { if (tripDto == null) { throw new ArgumentNullException(nameof(tripDto)); } if (tripDto.FromCityId == null) { throw new ArgumentNullException(nameof(tripDto.FromCityId)); } if (tripDto.ToCountryId == null) { throw new ArgumentNullException(nameof(tripDto.ToCountryId)); } var trip = new Trip { FromCityId = tripDto.FromCityId.Value, FromCountryId = tripDto.FromCountryId, ToCityId = tripDto.ToCityId <= 0 ? null : tripDto.ToCityId, ToCountryId = tripDto.ToCountryId.Value, UserId = tripDto.UserId, DateFrom = tripDto.DateFrom, DateTo = tripDto.DateTo, PreferredGender = tripDto.PreferredGender, Comment = tripDto.Comment, CreatedDate = DateTime.UtcNow }; return(await _tripStorage.CreateAsync(trip)); }
public async Task <IActionResult> AddNewTrip([FromBody] TripDto newTrip) { var trip = _mapper.Map <Trip>(newTrip); var retVal = await _tripRepository.AddTrip(trip); return(Ok(retVal)); }
protected override void OnNavigatedTo(NavigationEventArgs e) { TripDto trip = (TripDto)e.Parameter; currentTripId = trip.Id; ViewModel.GetItems(currentTripId); base.OnNavigatedTo(e); }
public async Task <IActionResult> UpdateTrip(string id, [FromBody] TripDto trip) { var updatedTrip = _mapper.Map <Trip>(trip); var retVal = await _tripRepository.UpdateTrip(id, updatedTrip); return(Ok(retVal)); }
public IActionResult UpdateTrip([FromBody] TripDto tripDto) { EnsureArg.IsNotNull(tripDto); var command = new UpdateTripCommand(tripDto); CommandDispatcher.Execute(command); return(NoContent()); }
public async Task Post_ReturnsOkResult() { var trip = new TripDto() { From = "Kyiv", To = "Poltava" }; var client = _factory.CreateClient(); var res = await client.PostAsJsonAsync("/api/trips", trip); res.StatusCode.Should().Be(HttpStatusCode.OK); }
private void PublishTripCreated(ref string input) { var trip = new TripDto { Car = input, Persons = new List <string>() }; Publish(SampleApiConfiguration.TripCreated, trip); input = ""; }
TripDto IConverter.MapTripTripDto(Trip tripFromRepo) { TripDto viajeRealizado = new TripDto() { AnnoDeLaVisita = tripFromRepo.DateVisited, IdPais = tripFromRepo.IdCountry, CodigoPais = tripFromRepo.Country.CountryCode, Pais = tripFromRepo.Country.Name, UrlFlag = tripFromRepo.Country.FlagUrl }; return(viajeRealizado); }
// TODO: 2 - Create a method that calls the Booking service private string CreateReservationOnBackendSystem(Reservation reservation) { IBookingService proxy = factory.CreateChannel(); try { (proxy as ICommunicationObject).Open(); TripDto departureFlight = new TripDto { FlightScheduleID = reservation.DepartureFlight.FlightScheduleID, Class = reservation.DepartureFlight.Class, Status = reservation.DepartureFlight.Status }; TripDto returnFlight = null; if (reservation.ReturnFlight != null) { returnFlight = new TripDto { FlightScheduleID = reservation.ReturnFlight.FlightScheduleID, Class = reservation.ReturnFlight.Class, Status = reservation.ReturnFlight.Status }; } ReservationDto request = new ReservationDto { DepartureFlight = departureFlight, ReturnFlight = null, ReservationDate = reservation.ReservationDate, TravelerId = reservation.TravelerId }; string confirmationCode = proxy.CreateReservation(request); (proxy as ICommunicationObject).Close(); return(confirmationCode); } catch (FaultException <ReservationCreationFault> fault) { HttpResponseMessage faultedResponse = Request.CreateResponse(HttpStatusCode.BadRequest, fault.Detail.Description); throw new HttpResponseException(faultedResponse); } catch (Exception) { (proxy as ICommunicationObject).Abort(); throw; } }
public List <TripParticipantDto> Search(string search) { var results = _eventParticipantService.TripParticipants(search); var participants = results.GroupBy(r => new { r.ParticipantId, r.ContactId, r.EmailAddress, r.Lastname, r.Nickname }).Select(x => new TripParticipantDto() { ParticipantId = x.Key.ParticipantId, ContactId = x.Key.ContactId, Email = x.Key.EmailAddress, Lastname = x.Key.Lastname, Nickname = x.Key.Nickname, ShowGiveButton = true, ShowShareButtons = false }).ToDictionary(y => y.ParticipantId); foreach (var result in results) { // check status of pledge for campaign var pledge = _mpPledgeService.GetPledgeByCampaignAndDonor(result.CampaignId, result.DonorId); if (pledge == null || pledge.PledgeStatusId == 3) { continue; } var tp = new TripDto { EventParticipantId = result.EventParticipantId, EventEnd = result.EventEndDate.ToString("MMM dd, yyyy"), EventId = result.EventId, EventStartDate = result.EventStartDate.ToUnixTime(), EventStart = result.EventStartDate.ToString("MMM dd, yyyy"), EventTitle = result.EventTitle, EventType = result.EventType, ProgramId = result.ProgramId, ProgramName = result.ProgramName, CampaignId = result.CampaignId, CampaignName = result.CampaignName, PledgeDonorId = result.DonorId }; var participant = participants[result.ParticipantId]; participant.Trips.Add(tp); } return(participants.Values.Where(x => x.Trips.Count > 0).OrderBy(o => o.Lastname).ThenBy(o => o.Nickname).ToList()); }
protected override void SetupMockingForTests() { _mockRepository = new Mock <IBaseRepository <Trip> >(); _mockMapper = new Mock <IMapper>(); _trip = new Trip { Id = Guid.NewGuid() }; _tripDto = new TripDto { Id = _trip.Id }; }
public async Task <IActionResult> Post([FromBody] TripDto trip) { if (ModelState.IsValid) { var newTrip = Mapper.Map <Trip>(trip); newTrip.UserName = User.Identity.Name; _unitOfWork.Trips.Add(newTrip); if (await _unitOfWork.CompleteAsync()) { return(Created($"api/trips/{trip.Name}", Mapper.Map <TripDto>(newTrip))); } } return(BadRequest("Failed to save the trip")); }
private void AddNudges(int nudgeCount) { var userIds = this.userService.GetAllUserIds(); for (int i = 0; i < nudgeCount; i++) { var forecast = new WeatherDto() { }; var trip = new TripDto(); // this.nudgeService.AddNudge(userIds[random.Next(userIds.Count)], (TransportationType)(random.Next(3)), forecast, trip); } }
public static async Task <TripDto> AddTrip(string title, DateTime startDate, DateTime endDate, ItineraryDto itinerary) { TripDto trip = new TripDto { Title = title, StartDate = startDate, EndDate = endDate, }; var result = await PutObject("/Trip/Create", trip); itinerary.TripId = result.Id; await CreateItinerary(itinerary); return(result); }
public IActionResult GetWishTrip(int id) { var TripFromRepo = TripsRepository.GetTrip(id); if (TripFromRepo == null) { return(NotFound()); } TripDto TripDone = CustomMapper.MapTripTripDto(TripFromRepo); return(Ok(TripDone)); }
private string CreateReservationOnBackendSystem(Reservation reservation) { IBookingService proxy = factory.CreateChannel(); try { (proxy as ICommunicationObject).Open(); TripDto departureFlight = new TripDto { FlightScheduleID = reservation.DepartureFlight.FlightScheduleID, Class = reservation.DepartureFlight.Class, Status = reservation.DepartureFlight.Status }; TripDto returnFlight = null; if (reservation.ReturnFlight != null) { returnFlight = new TripDto { FlightScheduleID = reservation.ReturnFlight.FlightScheduleID, Class = reservation.ReturnFlight.Class, Status = reservation.ReturnFlight.Status }; } ReservationDto request = new ReservationDto() { DepartureFlight = departureFlight, ReturnFlight = null, ReservationDate = reservation.ReservationDate, TravelerId = reservation.TravelerId }; string confirmationCode = proxy.CreateReservation(request); (proxy as ICommunicationObject).Close(); return(confirmationCode); } catch (Exception) { (proxy as ICommunicationObject).Abort(); throw; } }
public async Task <ActionResult <BaseResult> > UpdateAsync([FromBody, BindRequired] TripDto tripDto) { if (!ModelState.IsValid) { return(BadRequest()); } var login = HttpContext.User.Identity.Name; var userAuth = await _authService.GetActiveUserByLoginAsNoTrackingAsync(login); if (userAuth.ForceRelogin) { throw new UnauthorizedException(string.Empty); } tripDto.UserId = userAuth.UserId; return(await _tripService.UpdateAsync(tripDto)); }
private List <TripDto> GetTrips(Vuelo[] vuelos) { var flightList = new List <FlightDto>(); foreach (var flight in vuelos) { flightList.Add(GetFlightDto(flight)); } var trips = new List <TripDto>(); var trip = new TripDto() { Flights = flightList }; trips.Add(trip); return(trips); }
private Trip MapFromDatabase(TripDto tripDto) { Trip trip = new Trip(); trip.ArrivalTime = tripDto.ArrivalTime.Value; trip.DepartureTime = tripDto.DepartureTime.Value; trip.Train = this.queryHelper.SingleOrDefault <Train>(t => t.TrainNumber == tripDto.Train); trip.OriginStation = this.queryHelper.SingleOrDefault <Station>(st => st.Name == tripDto.OriginStation); trip.DestinationStation = this.queryHelper.SingleOrDefault <Station>(st => st.Name == tripDto.DestinationStation); trip.Status = tripDto.Status.HasValue ? tripDto.Status.Value : TripStatus.OnTime; if (!string.IsNullOrEmpty(tripDto.TimeDifference)) { trip.TimeDifference = TimeSpan.ParseExact(tripDto.TimeDifference, @"hh\:mm", CultureInfo.InvariantCulture); } return(trip); }
private Trip CreateTrip(TripDto tripDto) { Trip trip = new Trip { ArrivalTime = tripDto.ArrivalTime.Value, DepartureTime = tripDto.DepartureTime.Value, Train = this.helperMethods.SingleOrDefault <Train>(t => t.TrainNumber == tripDto.Train), OriginStation = this.helperMethods.SingleOrDefault <Station>(st => st.Name == tripDto.OriginStation), DestinationStation = this.helperMethods.SingleOrDefault <Station>(st => st.Name == tripDto.DestinationStation), Status = tripDto.Status ?? TripStatus.OnTime }; if (!string.IsNullOrEmpty(tripDto.TimeDifference)) { trip.TimeDifference = TimeSpan.ParseExact(tripDto.TimeDifference, @"hh\:mm", CultureInfo.InvariantCulture); } return(trip); }
public void testSetParameters() { string key = "keyTrip1"; string line = "lineTest1"; string path = "pathTest1"; int[] passingTimes = { 1, 2, 3, 4, 5 }; List <int> lPassingTimes = new List <int>(); lPassingTimes.AddRange(passingTimes); TripDto tdto = new TripDto(key, line, path, lPassingTimes); Assert.AreEqual(tdto.Key, key); Assert.AreEqual(tdto.Line, line); Assert.AreEqual(tdto.Path, path); foreach (int pt in lPassingTimes) { Assert.IsNotNull(tdto.PassingTimes.Contains(pt)); } }