public void CreateFake(FakeType fakeType) { TripViewModel fake; if (fakeType == FakeType.Trip) { TripViewModel fakeTrip = this.Items.FirstOrDefault(p => p.Identifier == -1); if (fakeTrip != null) this.Items.Remove(fakeTrip); fake = new TripViewModel() { Identifier = -1, Title = "New Trip?", Description = "Click here to add a trip", LocalPathImage = "Assets/NewTrip.png", }; } else { fake = new TripViewModel() { Identifier = -1, Title = "Comming Soon", Description = "We are working", LocalPathImage = "Assets/Suggestion.png", IsSuggestion = true, }; } fake.ItemGroups.Clear(); fake.ItemGroups = new ObservableCollection<CategoryViewModel>(); this.Items.Add(fake); }
public ManageTrip(TripViewModel tripViewModel) { this.InitializeComponent(); this.tbTitle.Text = "Update Trip"; InitializeFlyout(); this.tripViewModel = tripViewModel; this.txtTitle.Text = tripViewModel.Title; this.txtDescription.Text = tripViewModel.Description; this.txtCost.Text = tripViewModel.Cost.ToString(); cboYears.SelectedValue = tripViewModel.StartDate.Year; cboMonths.SelectedValue = this.cboMonths.Items[tripViewModel.StartDate.Month - 1]; cboDays.SelectedValue = tripViewModel.StartDate.Day; }
async public Task UpdateTrip(TripViewModel trip) { SQLite.SQLiteAsyncConnection context = new SQLite.SQLiteAsyncConnection(connectionString); List<ItemViewModel> result = new List<ItemViewModel>(); Item item = await context.Table<Item>().Where(p => p.Identifier == trip.Identifier).FirstOrDefaultAsync(); item.Image = trip.LocalPathImage; item.Title = trip.Title; item.Description = trip.Description; item.Cost = trip.Cost; item.StartDate = trip.StartDate; if (item != null) { await context.UpdateAsync(item); } }
public async Task<int> SaveTripAsync(TripViewModel trip) { SQLite.SQLiteAsyncConnection context = new SQLite.SQLiteAsyncConnection(connectionString); Item newItem = new Item() { Identifier = trip.Identifier, Title = trip.Title, Description = trip.Description, Cost = trip.Cost, EndDate = trip.EndDate, StartDate = trip.StartDate, Latitude = trip.Latitude, Longitude = trip.Longitude, Traveler = trip.Traveler.ToString(), Image = trip.LocalPathImage }; await context.InsertAsync(newItem); return newItem.Identifier; }
public static void SetSelectedTrip(TripViewModel trip) { _mainViewModel.SelectedTrip = trip; trip.SelectedItems = new ObservableCollection<ItemViewModel>(); }
private static void CreateFakeItem(TripViewModel trip) { CategoryViewModel category = trip.CreateCategory(Category.Things); if (category.Items.Count == 0) { ItemViewModel item = new ItemViewModel(); item.Identifier = -1; item.Title = "Note"; item.Description = "Add items from the botton toolbar"; item.Group = category; item.Trip = trip; category.Items.Add(item); } }
async public static Task<int> SaveTripAsync(TripViewModel trip) { int tripIdentifier = -1; if (trip.Identifier == -1) { tripIdentifier = await model.SaveTripAsync(trip); if (tripIdentifier != -1) { _mainViewModel.AllGroups[0].Items.Add(trip); _mainViewModel.AllGroups[0].CreateFake(FakeType.Trip); } } else { await model.UpdateTrip(trip); tripIdentifier = trip.Identifier; } return tripIdentifier; }
async private void btnSave_Click(object sender, RoutedEventArgs e) { try { this.txtStatusMessage.Visibility = Windows.UI.Xaml.Visibility.Visible; this.txtStatusMessage.Text = "Please wait..."; if (AreFieldsValid()) { if (tripViewModel == null) { TripViewModel newTrip = new TripViewModel() { Identifier = -1, Title = this.txtTitle.Text, LocalPathImage = "/Assets/Trip.png", Group = MainViewModel.GetGroup(0), Description = this.txtDescription.Text, Cost = Convert.ToInt64(this.txtCost.Text), Traveler = MainViewModel.GetTraveler(), StartDate = new DateTime( Convert.ToInt32(cboYears.SelectedItem), Convert.ToInt32(((PairViewModel)cboMonths.SelectedItem).Identifier + 1), Convert.ToInt32(cboDays.SelectedItem)) }; newTrip.Identifier = await MainViewModel.SaveTripAsync(newTrip); this.txtStatusMessage.Text = "Trip has been created"; } else { tripViewModel.Title = this.txtTitle.Text; tripViewModel.Description = this.txtDescription.Text; tripViewModel.Cost = Convert.ToInt64(this.txtCost.Text); tripViewModel.StartDate = new DateTime( Convert.ToInt32(cboYears.SelectedItem), Convert.ToInt32(((PairViewModel)cboMonths.SelectedItem).Identifier + 1), Convert.ToInt32(cboDays.SelectedItem)); await MainViewModel.SaveTripAsync(tripViewModel); this.txtStatusMessage.Text = "Trip has been updated"; } this.backButton_Click(sender, e); } } catch (Exception) { this.txtStatusMessage.Text = "Something is wrong, please review the fields and try again"; } }
private static void RemoveFakeTrip(TripViewModel item) { TripViewModel fake = item.Group.Items[item.Group.Items.Count - 1]; if (fake.Identifier == -1) item.Group.Items.Remove(fake); }