public CustomerDetailViewModel(Account account) { if (account == null) { Account = new Account(); Account.Industry = Account.IndustryTypes[0]; Account.OpportunityStage = Account.OpportunityStages[0]; this.Title = "New Account"; } else { Account = account; this.Title = "Account"; } this.Icon = "account.png"; _DataClient = DependencyService.Get<IDataClient>(); _GeoCodingService = DependencyService.Get<IGeoCodingService>(); MessagingCenter.Subscribe<Account>(this, MessagingServiceConstants.ACCOUNT, (Account) => { IsInitialized = false; }); }
public OrderDetailViewModel(Account account, Order order = null) { Account = account; if (order == null) { Order = new Order() { AccountId = Account.Id }; } else { Order = order; } this.Title = "Order Details"; _DataClient = DependencyService.Get<IDataClient>(); DependencyService.Get<ILocalize>(); MessagingCenter.Subscribe<Product>(this, MessagingServiceConstants.UPDATE_ORDER_PRODUCT, async catalogProduct => { Order.Item = catalogProduct.Name; Order.Price = catalogProduct.Price; OrderItemImageUrl = null; await ExecuteLoadOrderItemImageUrlCommand(); // this is to account for Android not calling OnAppearing() when the product selection modal disappears. OnPropertyChanged("Order"); }); }
public CustomerTabbedPage(INavigation navigation, Account account) { // since we're modally presented this tabbed view (because Android doesn't natively support nested tabs), // this tool bar item provides a way to get back to the Customers list ToolbarItems.Add(new ToolbarItem(TextResources.Customers_Orders_CustomerTabbedPage_BackToCustomers, null, async () => await navigation.PopModalAsync())); CustomerDetailPage customerDetailPage = new CustomerDetailPage() { BindingContext = new CustomerDetailViewModel(account) { Navigation = this.Navigation }, Title = TextResources.Customers_Detail_Tab_Title, Icon = new FileImageSource() { File = "CustomersTab" } // only used on iOS }; CustomerOrdersPage customerOrdersPage = new CustomerOrdersPage() { BindingContext = new OrdersViewModel(account) { Navigation = this.Navigation }, Title = TextResources.Customers_Orders_Tab_Title, Icon = new FileImageSource() { File = "ProductsTab" } // only used on iOS }; CustomerSalesPage customerSalesPage = new CustomerSalesPage() { BindingContext = new CustomerSalesViewModel(account) { Navigation = this.Navigation }, Title = TextResources.Customers_Sales_Tab_Title, Icon = new FileImageSource() { File = "SalesTab" } // only used on iOS }; Children.Add(customerDetailPage); Children.Add(customerOrdersPage); Children.Add(customerSalesPage); }
public OrdersViewModel(Account account) { Account = account; _Orders = new List<Order>(); _DataClient = DependencyService.Get<IDataService>(); OrderGroups = new ObservableCollection<Grouping<Order, string>>(); MessagingCenter.Subscribe<Order>(this, MessagingServiceConstants.SAVE_ORDER, order => { var index = _Orders.IndexOf(order); if (index >= 0) { _Orders[index] = order; } else { _Orders.Add(order); } GroupOrders(); }); }
public LeadDetailViewModel(INavigation navigation, Account lead = null) { if (navigation == null) { throw new ArgumentNullException("navigation", "An instance of INavigation must be passed to the LeadDetailViewModel constructor."); } Navigation = navigation; if (lead == null) { Lead = new Account(); this.Title = TextResources.Leads_NewLead; } else { Lead = lead; this.Title = lead.Company; } this.Icon = "contact.png"; _DataClient = DependencyService.Get<IDataClient>(); _GeoCodingService = DependencyService.Get<IGeoCodingService>(); }
public async Task ExecuteLoadSeedDataCommand(Account account) { if (IsBusy) return; IsBusy = true; if (!_DataClient.IsSeeded) { await _DataClient.SeedLocalDataAsync(); } Orders.Clear(); Orders.AddRange((await _DataClient.GetAllOrdersAsync()).Where(x => x.AccountId == account.Id)); WeeklySalesChartDataPoints.Clear(); WeeklySalesChartDataPoints.AddRange((await _ChartDataService.GetWeeklySalesDataPointsAsync(Orders)).OrderBy(x => x.DateStart).Select(x => new ChartDataPoint(x.DateStart.ToString("d MMM"), x.Amount))); CategorySalesChartDataPoints.Clear(); CategorySalesChartDataPoints.AddRange((await _ChartDataService.GetCategorySalesDataPointsAsync(Orders, _Account)).OrderBy(x => x.XValue)); WeeklySalesAverage = String.Format("{0:C}", WeeklySalesChartDataPoints.Average(x => x.YValue)); IsBusy = false; }
public CustomerSalesViewModel(Account account) { _Account = account; _DataClient = DependencyService.Get<IDataService>(); _ChartDataService = DependencyService.Get<IChartDataService>(); Orders = new ObservableCollection<Order>(); WeeklySalesChartDataPoints = new ObservableCollection<ChartDataPoint>(); CategorySalesChartDataPoints = new ObservableCollection<ChartDataPoint>(); IsInitialized = false; }
public async Task<List<ChartDataPoint>> GetCategorySalesDataPointsAsync(IEnumerable<Order> orders, Account account = null, int numberOfWeeks = 6, bool isOpen = false) { // get top-level categories by passing no parent categoryId var categories = await _DataClient.GetCategoriesAsync(); List<ChartDataPoint> categorySalesDataPoints = new List<ChartDataPoint>(); orders = (account == null) ? orders : orders.Where(order => order.AccountId == account.Id); foreach (var category in categories) { double amount = await GetOrderTotalForCategoryAsync(orders, category, numberOfWeeks, isOpen); categorySalesDataPoints.Add(new ChartDataPoint(category.Name, amount)); } return categorySalesDataPoints; }
async Task PushTabbedLeadPage(Account lead = null) { LeadDetailViewModel viewModel = new LeadDetailViewModel(Navigation, lead); TabbedPage tabbedPage = new TabbedPage(); tabbedPage.ToolbarItems.Add( new ToolbarItem(TextResources.Save, null, async () => { var answer = await DisplayAlert( title: TextResources.Leads_SaveConfirmTitle, message: TextResources.Leads_SaveConfirmDescription, accept: TextResources.Save, cancel: TextResources.Cancel); if (answer) { viewModel.SaveLeadCommand.Execute(null); await Navigation.PopModalAsync(); } })); tabbedPage.ToolbarItems.Add( new ToolbarItem(TextResources.Exit, null, async () => { { var answer = await DisplayAlert( title: TextResources.Leads_ExitConfirmTitle, message: TextResources.Leads_ExitConfirmDescription, accept: TextResources.Exit_and_Discard, cancel: TextResources.Cancel); if (answer) { await Navigation.PopModalAsync(); } } })); tabbedPage.Children.Add(new LeadDetailPage() { BindingContext = viewModel, Title = TextResources.Details, Icon = new FileImageSource() { File = "LeadDetailTab" } // only used on iOS }); tabbedPage.Children.Add(new LeadContactDetailPage() { BindingContext = viewModel, Title = TextResources.Contact, Icon = new FileImageSource() { File = "LeadContactDetailTab" } // only used on iOS }); NavigationPage navPage = new NavigationPage(tabbedPage); await Navigation.PushModalAsync(navPage); }
public CustomerMapViewModel(Account account) { _GeoCoder = new Geocoder(); }
async Task PushTabbedLeadPage(Account lead = null) { LeadDetailViewModel viewModel = new LeadDetailViewModel(Navigation, lead); var leadDetailPage = new LeadDetailPage() { BindingContext = viewModel, Title = TextResources.Details, }; if (Device.OS == TargetPlatform.iOS) leadDetailPage.Icon = Icon = new FileImageSource() { File = "LeadDetailTab" }; if (lead != null) { leadDetailPage.Title = lead.Company; } else { leadDetailPage.Title = "New Lead"; } leadDetailPage.ToolbarItems.Add( new ToolbarItem(TextResources.Save, "save.png", async () => { if (string.IsNullOrWhiteSpace(viewModel.Lead.Company)) { await DisplayAlert("Missing Information", "Please fill in the lead's company to continue", "OK"); return; } var answer = await DisplayAlert( title: TextResources.Leads_SaveConfirmTitle, message: TextResources.Leads_SaveConfirmDescription, accept: TextResources.Save, cancel: TextResources.Cancel); if (answer) { viewModel.SaveLeadCommand.Execute(null); await Navigation.PopAsync(); } })); await Navigation.PushAsync(leadDetailPage); }
public async Task DeleteAccountAsync(Account item) { try { await _AccountTable.DeleteAsync(item); } catch (MobileServiceInvalidOperationException ex) { Insights.Report(ex, Insights.Severity.Error); Debug.WriteLine(@"ERROR {0}", ex.Message); } catch (Exception ex2) { Insights.Report(ex2, Insights.Severity.Error); Debug.WriteLine(@"ERROR {0}", ex2.Message); } }
public async Task SaveAccountAsync(Account item) { try { using (var handle = Insights.TrackTime("TimeToSaveAccount")) { if (item.Id == null) await _AccountTable.InsertAsync(item); else await _AccountTable.UpdateAsync(item); } } catch (MobileServiceInvalidOperationException ex) { Insights.Report(ex, Insights.Severity.Error); Debug.WriteLine(@"ERROR {0}", ex.Message); } catch (Exception ex2) { Insights.Report(ex2, Insights.Severity.Error); Debug.WriteLine(@"ERROR {0}", ex2.Message); } }