Example #1
0
        public static TripSummary GetTripSummary(TripResponse trip)
        {
            try
            {
                double distance = 0;

                if (trip.TripDetails == null || trip.TripDetails.Count < 2)
                {
                    return(new TripSummary());
                }

                List <TripDetailResponse> details = trip.TripDetails.ToList();
                for (int i = 0; i < details.Count - 1; i++)
                {
                    Position a = new Position(details[i].Latitude, details[i].Longitude);
                    Position b = new Position(details[i + 1].Latitude, details[i + 1].Longitude);
                    distance += GetDistance(a, b, UnitOfLength.Kilometers) * 1000;
                }

                decimal value = (decimal)(3600 + Math.Truncate(distance / 78) * 110);

                return(new TripSummary
                {
                    Distance = distance,
                    Time = details[details.Count - 1].Date.Subtract(details[0].Date),
                    Value = value < 5600 ? 5600 : value
                });
            }
            catch
            {
                return(new TripSummary {
                    Value = 5600
                });
            }
        }
Example #2
0
        public async Task <TripResponse> GetAuthorizedListAsync(FilterTripRequest filterTripRequest, int userId, string currentCulture)
        {
            if (filterTripRequest == null)
            {
                throw new ArgumentNullException(nameof(filterTripRequest));
            }

            var trips = await _tripStorage.GetAuthorizedListAsync(filterTripRequest, userId);

            var pathToUserDirectory = Path.Combine(_appEnvironment.WebRootPath, "Photos", "Users");

            var tripsForListDto = new List <TripForListDto>();

            foreach (var trip in trips)
            {
                var targetPath   = Path.Combine(pathToUserDirectory, $"{trip.User.Login}");
                var targetImages = new List <string>();
                if (Directory.Exists(targetPath))
                {
                    targetImages = Directory.GetFiles(targetPath, "*_icon.jpeg").ToList();
                }
                var tripDto = new TripForListDto
                {
                    Id           = trip.Id,
                    UserName     = trip.User.FirstName,
                    DateFrom     = trip.DateFrom,
                    DateTo       = trip.DateTo,
                    IsCompleted  = trip.IsCompleted,
                    IsDeleted    = trip.IsDeleted,
                    UserLogin    = trip.User.Login,
                    ImageUri     = $"https://www.amver.net/Photos/Countries/{trip.ToCountry.Name}/{trip.ToCountry.Name}_main.png",
                    UserImageUri = targetImages.Any() ? $"https://www.amver.net/Photos/Users/{trip.User.Login}/{Path.GetFileName(targetImages.First())}" : Path.Combine("https://www.amver.net", "images", "userAccountIcon.png")
                };
                switch (currentCulture)
                {
                case Cultures.Ru:
                    tripDto.FromCity    = trip.FromCity.ruRu;
                    tripDto.FromCountry = trip.FromCountry == null ? string.Empty : trip.FromCity.Country.ruRu;
                    tripDto.ToCity      = trip.ToCity == null ? string.Empty : trip.ToCity.ruRu;
                    tripDto.ToCountry   = trip.ToCountry.ruRu;
                    break;

                default:
                    tripDto.FromCity    = trip.FromCity.Name;
                    tripDto.FromCountry = trip.FromCountry == null ? string.Empty : trip.FromCity.Country.Name;
                    tripDto.ToCity      = trip.ToCity == null ? string.Empty : trip.ToCity.Name;
                    tripDto.ToCountry   = trip.ToCountry.Name;
                    break;
                }
                tripsForListDto.Add(tripDto);
            }

            var tripResponse = new TripResponse
            {
                Trips = tripsForListDto,
                Count = tripsForListDto.Count
            };

            return(tripResponse);
        }
Example #3
0
        public IEnumerable <TripResponse> GetActiveTrips()
        {
            List <TripResponse> respuesta = new List <TripResponse>();
            DateTime            fechaHoy  = DateTime.Now;

            IList <Trip> Trips = (from i in _context.Trip
                                  where i.FechaHasta > fechaHoy
                                  select i).ToList <Trip>();

            foreach (Trip viaje in Trips)
            {
                TripResponse item = new TripResponse();
                item.Ida              = viaje.Ida.ToString("dd/MM/yyyy");
                item.Vuelta           = viaje.Vuelta.ToString("dd/MM/yyyy");
                item.FechaDesde       = viaje.FechaDesde.ToString("dd/MM/yyyy");
                item.FechaHasta       = viaje.FechaHasta.ToString("dd/MM/yyyy");
                item.NotasImportantes = viaje.NotasImportantes;
                item.Estado           = viaje.Status.Nombre;
                item.Reserva          = viaje.CodigoReserva;
                item.Aerolinea        = viaje.Airline.Nombre;
                item.NombreViajero    = viaje.User.Nombre;
                item.ViajeId          = viaje.Id;
                respuesta.Add(item);
            }

            return(respuesta);
        }
 public NewTripDetailPageViewModel(INavigationService navigationService, IApiService apiService)
     : base(navigationService)
 {
     _navigationService = navigationService;
     _apiService        = apiService;
     _trip     = new TripResponse();
     Title     = "Add New Costs to Trip";
     IsEnabled = true;
     IsRunning = false;
 }
Example #5
0
 public DeleteExpensePageViewModel(INavigationService navigationService,
                                   IApiService apiService) : base(navigationService)
 {
     _navigationService = navigationService;
     _apiService        = apiService;
     Title     = Languages.DeleteExpense;
     _trip     = JsonConvert.DeserializeObject <TripResponse>(Settings.TripSelected);
     _user     = JsonConvert.DeserializeObject <UserResponse>(Settings.User);
     IsRunning = false;
     IsEnabled = true;
 }
Example #6
0
        public async Task <TripResponse> GetListByUserIdAsync(int userId, string currentCulture)
        {
            if (userId <= 0)
            {
                throw new ArgumentOutOfRangeException(nameof(userId));
            }

            var trips = await _tripStorage.GetByUserIdAsync(userId);

            var pathToDirectory     = Path.Combine(_appEnvironment.ContentRootPath, "wwwroot", "Photos", "Countries");
            var pathToUserDirectory = Path.Combine(_appEnvironment.WebRootPath, "Photos", "Users");

            var tripsForListDto = new List <TripForListDto>();

            foreach (var trip in trips)
            {
                var tripDto = new TripForListDto
                {
                    Id          = trip.Id,
                    UserName    = trip.User.FirstName,
                    DateFrom    = trip.DateFrom,
                    DateTo      = trip.DateTo,
                    IsCompleted = trip.IsCompleted,
                    IsDeleted   = trip.IsDeleted,
                    UserLogin   = trip.User.Login,
                    ImageUri    = $"https://www.amver.net/Photos/Countries/{trip.ToCountry.Name}/{trip.ToCountry.Name}_main.png"
                };
                switch (currentCulture)
                {
                case Cultures.Ru:
                    tripDto.FromCity    = trip.FromCity.ruRu;
                    tripDto.FromCountry = trip.FromCountry == null ? string.Empty : trip.FromCity.Country.ruRu;
                    tripDto.ToCity      = trip.ToCity == null ? string.Empty : trip.ToCity.ruRu;
                    tripDto.ToCountry   = trip.ToCountry.ruRu;
                    break;

                default:
                    tripDto.FromCity    = trip.FromCity.Name;
                    tripDto.FromCountry = trip.FromCountry == null ? string.Empty : trip.FromCity.Country.Name;
                    tripDto.ToCity      = trip.ToCity == null ? string.Empty : trip.ToCity.Name;
                    tripDto.ToCountry   = trip.ToCountry.Name;
                    break;
                }
                tripsForListDto.Add(tripDto);
            }

            var tripResponse = new TripResponse
            {
                Trips = tripsForListDto,
                Count = tripsForListDto.Count
            };

            return(tripResponse);
        }
Example #7
0
 public NewExpensePageViewModel(INavigationService navigationService, IApiService apiService, IFilesHelper filesHelper) : base(navigationService)
 {
     _navigationService = navigationService;
     _apiService        = apiService;
     _filesHelper       = filesHelper;
     _trip          = new TripResponse();
     _tripDetailsId = new TripDetailsResponse();
     Title          = "Add New Expense";
     IsEnabled      = true;
     IsRunning      = false;
     Image          = App.Current.Resources["UrlNoImage"].ToString();
 }
 public TripEntity ToTriEntity(TripResponse tripResponse, UserEntity user)
 {
     return(new TripEntity
     {
         Id = tripResponse.Id,
         Name = tripResponse.Name,
         Description = tripResponse.Description,
         StartDate = tripResponse.StartDate.ToUniversalTime(),
         EndDate = tripResponse.EndDate.ToUniversalTime(),
         User = user
     });
 }
        public async Task <Response> AddExpense(string urlBase,
                                                string servicePrefix,
                                                string controller,
                                                string tokenType,
                                                string accessToken,
                                                ExpenseRequest expenseRequest)
        {
            try
            {
                string        requestString = JsonConvert.SerializeObject(expenseRequest);
                StringContent content       = new StringContent(requestString, Encoding.UTF8, "application/json");
                HttpClient    client        = new HttpClient
                {
                    BaseAddress = new Uri(urlBase)
                };
                client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue(tokenType, accessToken);
                string url = $"{servicePrefix}{controller}";
                HttpResponseMessage response = await client.PostAsync(url, content);

                string result = await response.Content.ReadAsStringAsync();

                if (!response.IsSuccessStatusCode)
                {
                    return(new Response
                    {
                        IsSuccess = false,
                        Message = result,
                    });
                }
                TripResponse tripResponse = JsonConvert.DeserializeObject <TripResponse>(result);
                return(new Response
                {
                    IsSuccess = true,
                    Result = tripResponse
                });
            }
            catch (Exception ex)
            {
                return(new Response
                {
                    IsSuccess = false,
                    Message = ex.Message
                });
            }
        }
        public async Task <IActionResult> Create([FromBody] CreateTripRequest tripRequest)
        {
            var trip = new Trip {
                Name = tripRequest.Name
            };

            await _tripService.CreateTripAsync(trip);

            var baseUrl = $"{HttpContext.Request.Scheme}://{HttpContext.Request.Host.ToUriComponent()}";

            var locationUri = baseUrl + "/" + ApiRoutes.Trips.Get.Replace("{tripId}", trip.Id.ToString());

            var response = new TripResponse {
                Id = trip.Id
            };

            return(Created(locationUri, response));
        }
Example #11
0
 public AddExpensePageViewModel(INavigationService navigationService,
                                IApiService apiService,
                                IFilesHelper filesHelper) : base(navigationService)
 {
     _navigationService = navigationService;
     _apiService        = apiService;
     _filesHelper       = filesHelper;
     Title        = Languages.AddExpense;
     Image        = App.Current.Resources["UrlNoImage"].ToString();
     IsRunning    = false;
     IsEnabled    = true;
     _user        = JsonConvert.DeserializeObject <UserResponse>(Settings.User);
     _trip        = JsonConvert.DeserializeObject <TripResponse>(Settings.TripSelected);
     ExpenseTypes = new ObservableCollection <ExpenseType>(CombosHelper.GetExpenseTypes());
     Expense      = new ExpenseRequest
     {
         Date = DateTime.UtcNow.ToLocalTime()
     };
 }
Example #12
0
        public TripResponse NewTrip(TripRequest datosTrip)
        {
            var  user  = _context.User.SingleOrDefault(c => c.Email == datosTrip.Email);
            Trip viaje = new Trip();

            viaje.Vuelta           = datosTrip.Vuelta.Date;
            viaje.Ida              = datosTrip.Ida.Date;
            viaje.FechaDesde       = datosTrip.ItemDesde.Date;
            viaje.FechaHasta       = datosTrip.ItemHasta.Date;
            viaje.NotasImportantes = datosTrip.NotasImportantes;
            viaje.UserId           = user.Id;
            viaje.UsAddressId      = datosTrip.UsAddressId;
            viaje.StatusId         = datosTrip.StatusId;
            viaje.CodigoReserva    = datosTrip.CodigoReserva;
            viaje.AirlineId        = datosTrip.AirlineId;
            _context.Trip.Add(viaje);
            _context.SaveChanges();
            TripResponse respuesta = new TripResponse();

            return(respuesta);
        }
Example #13
0
        public async Task <Response> GetTripAsync(int id, string urlBase, string servicePrefix, string controller)
        {
            try
            {
                HttpClient client = new HttpClient
                {
                    BaseAddress = new Uri(urlBase),
                };

                string url = $"{servicePrefix}{controller}/{id}";
                HttpResponseMessage response = await client.GetAsync(url);

                string result = await response.Content.ReadAsStringAsync();

                if (!response.IsSuccessStatusCode)
                {
                    return(new Response
                    {
                        IsSuccess = false,
                        Message = result,
                    });
                }

                TripResponse model = JsonConvert.DeserializeObject <TripResponse>(result);

                return(new Response
                {
                    IsSuccess = true,
                    Result = model
                });
            }
            catch (Exception ex)
            {
                return(new Response
                {
                    IsSuccess = false,
                    Message = ex.Message
                });
            }
        }
Example #14
0
        public async Task <Response> GetTripAsync(string urlBase, string servicePrefix, string controller, int id, string tokenType, string accessToken)
        {
            try
            {
                HttpClient client = new HttpClient
                {
                    BaseAddress = new Uri(urlBase)
                };

                client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue(tokenType, accessToken);
                string url = $"{servicePrefix}{controller}/{id}";
                HttpResponseMessage response = await client.GetAsync(url);

                string answer = await response.Content.ReadAsStringAsync();

                if (!response.IsSuccessStatusCode)
                {
                    return(new Response
                    {
                        IsSuccess = false,
                        Message = answer,
                    });
                }

                TripResponse trip = JsonConvert.DeserializeObject <TripResponse>(answer);
                return(new Response
                {
                    IsSuccess = true,
                    Result = trip,
                });
            }
            catch (Exception ex)
            {
                return(new Response
                {
                    IsSuccess = false,
                    Message = ex.Message,
                });
            }
        }
Example #15
0
        public void DrawMap(TripResponse trip)
        {
            if (trip.SourceLatitude != 0 && trip.SourceLongitude != 0)
            {
                Position position = new Position(trip.SourceLatitude, trip.SourceLongitude);
                AddPin(position, trip.Source, Languages.StartTrip, PinType.Place);
                MoveMap(position);
            }

            if (trip.TargetLatitude != 0 && trip.TargetLongitude != 0)
            {
                Position position = new Position(trip.TargetLatitude, trip.TargetLongitude);
                AddPin(position, trip.Target, Languages.EndTrip, PinType.Place);
                MoveMap(position);
            }

            for (int i = 0; i < trip.TripDetails.Count - 1; i++)
            {
                Position a = new Position(trip.TripDetails[i].Latitude, trip.TripDetails[i].Longitude);
                Position b = new Position(trip.TripDetails[i + 1].Latitude, trip.TripDetails[i + 1].Longitude);
                DrawLine(a, b);
            }
        }
Example #16
0
        public IEnumerable <TripResponse> GetWycieczkiDoWeryfikacji([FromRoute] int id)
        {
            var permissions   = _context.UprawnieniePrzodownika.ToList();
            var tripsToVerify = _context.GradedTripsWithIncludedObjs();
            var score         = _tripListService.GetTripsToVerifyByGuide(tripsToVerify, permissions, id).Select(t => TripResponse.BuildFromModel(t));

            return(score);
        }
Example #17
0
 public Trip(TripResponse tripResponseModel) =>