Exemplo n.º 1
0
        public async Task <GoogleCloudDialogflowV2WebhookResponse> GetDistance(GoogleCloudDialogflowV2WebhookRequest request)
        {
            int distance = _trackingHandler.GetDistance(request.ToFilteredBinding(true));

            return(new GoogleCloudDialogflowV2WebhookResponse()
            {
                FulfillmentText = $"You covered {FormatDistance(distance)}"
            });
        }
 public int GetDistance([FromQuery] FilteredBinding binding) => _trackingHandler.GetDistance(binding);
Exemplo n.º 3
0
        public View.Trip.Trip GetSingle(string valueId)
        {
            using (var context = GetMainContext())
            {
                var trip = context.Trips.WhereUser(UserId)
                           .Include(x => x.Cities)
                           .ThenInclude(x => x.Country)
                           .Include(x => x.Files)
                           .Include($"{nameof(Database.Travel.Trip.Pois)}.{nameof(TripPoi.Poi)}")
                           .SingleOrDefault(x => x.ValueId == valueId);

                var excludedExpenseIds = context.TripExpensesExcluded.Where(x => x.TripId == trip.Id)
                                         .Select(x => x.ExpenseId)
                                         .ToList();

                var includedExpenseIds = context.TripExpensesIncluded.Where(x => x.TripId == trip.Id)
                                         .Select(x => x.ExpenseId)
                                         .ToList();

                var userExpenses = context.Expenses.WhereUser(UserId);

                var expensesWithExcluded = userExpenses.Where(x => trip.TimestampStart.Date <= x.Date && trip.TimestampEnd.Date >= x.Date)
                                           .Where(x => !excludedExpenseIds.Contains(x.Id));

                var expensesIncluded = userExpenses.Where(x => includedExpenseIds.Contains(x.Id));

                var expenseIds = expensesWithExcluded.Union(expensesIncluded)
                                 .OrderBy(x => x.Date)
                                 .Select(x => x.Id)
                                 .ToList();

                var expenses = context.Expenses.Where(x => expenseIds.Contains(x.Id))
                               .IncludeAll()
                               .OrderBy(x => x.Date)
                               .ToList();

                decimal totalSpent = 0;

                if (expenseIds.Any())
                {
                    using (var db = GetSqlConnection())
                    {
                        int    targetCurrencyId = context.GetCurrencyId(null, UserId);
                        string sql = SqlLoader.Load(SqlScripts.GetExpenseSumInDefaultCurrency);

                        var query = new GetExpenseSumQuery()
                        {
                            ExpenseIds       = expenseIds,
                            TargetCurrencyId = targetCurrencyId,
                            UserId           = UserId
                        };

                        totalSpent = db.ExecuteScalar <decimal>(sql, query);
                    }
                }

                var tripView = new View.Trip.Trip(trip)
                {
                    Expenses   = expenses.Select(x => new View.Expense.Expense(x)),
                    Distance   = _trackingHandler.GetDistance(new Model.Binding.FilteredBinding(trip.TimestampStart, trip.TimestampEnd)),
                    TotalSpent = totalSpent
                };

                return(tripView);
            }
        }