Beispiel #1
0
        public static void FillDay(DayOfTrip dayOfTrip, List <ActivityPoint> remainedActivities, Dictionary <eActivityType, int> preferences)
        {
            TimeWindow timeWindow;

            //sort first by near to main acitivity then by user prefrences
            //TODO: add sort by rank
            var sortedByLocationAcitivities = remainedActivities.OrderBy(a =>
                                                                         LocationUtils.HaversineDistance(new Location(a.GEPSLatitude, a.GEPSLongtitude),
                                                                                                         new Location(dayOfTrip.MainActivity.Activity.GEPSLatitude, dayOfTrip.MainActivity.Activity.GEPSLongtitude)))
                                              .ThenByDescending(a => GetMatchGrade(a, preferences)).ToList();

            while ((timeWindow = dayOfTrip.GetNextEmptyTimeWindow()) != null)
            {
                List <ActivityTimeSlot> activities = null;
                foreach (var activity in sortedByLocationAcitivities)
                {
                    if ((activities = TryFindTimeForActivityAndTravel(activity, timeWindow)) != null)
                    {
                        dayOfTrip.AppendActivities(activities);
                        sortedByLocationAcitivities.Remove(activity);
                        remainedActivities.Remove(activity);
                        break;
                    }
                }

                if (activities == null)
                {
                    dayOfTrip.AddActivity(new ActivityTimeSlot(timeWindow.TimeSlot, null));
                }
            }

            dayOfTrip.SortedActivities.RemoveAll(a => a.Activity == null && a.IsTraveling == false); //Remove empty time slots
        }
        /// <summary>
        /// Handles the Click event of the UpdateDayOfTrip control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="RoutedEventArgs"/> instance containing the event data.</param>
        public async void UpdateDayOfTrip_Click(object sender, RoutedEventArgs e)
        {
            var day = new DayOfTrip
            {
                TripDayId      = DayId,
                Day            = Day,
                City           = City,
                Hotel          = Hotel,
                Dinner         = Dinner,
                MoneySpent     = Money,
                AdditionalInfo = Info,
                TripId         = TripId
            };

            using (var client = new System.Net.Http.HttpClient())
            {
                client.BaseAddress = new Uri(@"http://localhost:10051/api/");

                var content = JsonConvert.SerializeObject(day);

                var httpContent = new StringContent(content, Encoding.UTF8, "application/json");

                var json = await client.PutAsync("dayoftrips/" + day.TripDayId, httpContent);

                var nav = WindowWrapper.Current().NavigationServices.FirstOrDefault();
                nav.Navigate(typeof(Views.GetTripPage));
            }
        }
        public async Task <IHttpActionResult> PutDayOfTrip(int id, DayOfTrip dayOfTrip)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != dayOfTrip.TripDayId)
            {
                return(BadRequest());
            }

            db.Entry(dayOfTrip).State = EntityState.Modified;

            try
            {
                await db.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!DayOfTripExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Beispiel #4
0
        public static Trip GetTripPlan(UserRequest userRequest)
        {
            var trip = new Trip();

            using (var context = new ActivityPointsDbContext())
            {
                var activities       = context.ActivityPoints.ToList();
                var nearByActivities = activities.Where(a => IsNearBy(a, userRequest.VacationDetails.SleepLocation, nearByDistanceKm)).ToList();

                trip.DayTrips = new List <DayOfTrip>();

                for (int i = 0; i < userRequest.VacationDetails.Days; i++)
                {
                    if (nearByActivities.Count == 0)
                    {
                        break;
                    }

                    var mainActivity = nearByActivities.Aggregate((currMax, a) =>
                                                                  currMax == null || GetMatchGrade(a, userRequest.Preferences) <
                                                                  GetMatchGrade(currMax, userRequest.Preferences)
                            ? a
                            : currMax);
                    var day = new DayOfTrip(userRequest.Preferences[eActivityType.Intencity], mainActivity);
                    nearByActivities.Remove(mainActivity);
                    FillDay(day, nearByActivities, userRequest.Preferences);
                    trip.DayTrips.Add(day);
                }
            }

            return(trip);
        }
        /// <summary>
        /// Adds a day of trip to the database when button clicked.
        /// </summary>
        public async void AddDay_Click()
        {
            if (SelectedTrip == null)
            {
                var dialog = new MessageDialog("You must choose a trip from the dropdown");
                dialog.Commands.Add(new UICommand("Ok")
                {
                    Id = 0
                });

                dialog.CancelCommandIndex = 0;

                var result = await dialog.ShowAsync();

                return;
            }
            TripId = await GetId();

            if (Day == 0 || City == null || Hotel == null || Dinner == null || Info == null || City == "" || Hotel == "" || Dinner == "" || Info == "")
            {
                var dialog = new MessageDialog("You must fill all fields");
                dialog.Commands.Add(new UICommand("Ok")
                {
                    Id = 0
                });

                dialog.CancelCommandIndex = 0;

                var result = await dialog.ShowAsync();

                return;
            }
            var day = new DayOfTrip
            {
                Day            = Day,
                City           = City,
                Hotel          = Hotel,
                Dinner         = Dinner,
                MoneySpent     = Money,
                AdditionalInfo = Info,
                TripId         = TripId
            };

            using (var client = new System.Net.Http.HttpClient())
            {
                client.BaseAddress = new Uri(@"http://localhost:10051/api/");

                var content = JsonConvert.SerializeObject(day);

                var httpContent = new StringContent(content, Encoding.UTF8, "application/json");

                var json = await client.PostAsync("dayoftrips", httpContent);

                var nav = WindowWrapper.Current().NavigationServices.FirstOrDefault();
                nav.Navigate(typeof(Views.GetTripPage));
            }
        }
Beispiel #6
0
        public async Task <DayOfTrip> Update(DayOfTrip input)
        {
            using (var conn = new SqlConnection(AppSettings.ConnectionString))
            {
                await conn.ExecuteAsync(_sql.Update(input));

                return(await ById(input.Id));
            }
        }
Beispiel #7
0
        public async Task <DayOfTrip> Add(DayOfTrip input)
        {
            using (var conn = new SqlConnection(AppSettings.ConnectionString))
            {
                var id = await conn.QueryFirstOrDefaultAsync <int>(_sql.Add(input));

                return(await ById(id));
            }
        }
 public string Update(DayOfTrip input)
 {
     return($@"
         update {Table} set 
         Day = '{(int)input.Day}', 
         TurnoverId = '{input.TripId}', 
         where id = {input.Id}
     ");
 }
 public string Add(DayOfTrip input)
 {
     return($@"
         insert into {Table} 
         ([Day], [TripId]) 
         values
         ('{(int)input.Day}', '{input.TripId}')
         SELECT SCOPE_IDENTITY()
     ");
 }
        public async Task <IHttpActionResult> GetDayOfTrip(int id)
        {
            DayOfTrip dayOfTrip = await db.Days.FindAsync(id);

            if (dayOfTrip == null)
            {
                return(NotFound());
            }

            return(Ok(dayOfTrip));
        }
        public async Task <IHttpActionResult> PostDayOfTrip(DayOfTrip dayOfTrip)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.Days.Add(dayOfTrip);
            await db.SaveChangesAsync();

            return(CreatedAtRoute("DefaultApi", new { id = dayOfTrip.TripDayId }, dayOfTrip));
        }
        public async Task <IHttpActionResult> DeleteDayOfTrip(int id)
        {
            DayOfTrip dayOfTrip = await db.Days.FindAsync(id);

            if (dayOfTrip == null)
            {
                return(NotFound());
            }

            db.Days.Remove(dayOfTrip);
            await db.SaveChangesAsync();

            return(Ok(dayOfTrip));
        }
        public List <DayOfTrip> GetInfo(string query, SqlConnection conn, string tripName)
        {
            List <DayOfTrip> result = new List <DayOfTrip>();

            using (SqlCommand Command = new SqlCommand(query, conn))
            {
                Command.Parameters.AddWithValue("name", tripName);
                try
                {
                    conn.Open();
                    SqlDataReader rdr = Command.ExecuteReader();
                    while (rdr.Read())
                    {
                        var Day = new DayOfTrip
                        {
                            TripDayId      = rdr.GetInt32(0),
                            Day            = rdr.GetInt32(1),
                            City           = rdr.GetString(2),
                            Hotel          = rdr.GetString(3),
                            Dinner         = rdr.GetString(4),
                            MoneySpent     = rdr.GetInt32(5),
                            AdditionalInfo = rdr.GetString(6),
                            TripId         = rdr.GetInt32(7)
                        };
                        result.Add(Day);
                    }

                    return(result);
                }
                catch (Exception e)
                {
                    System.Diagnostics.Debug.WriteLine(e);
                }
                return(result);
            }
        }