예제 #1
0
        static async Task ExecuteSwipeToDeleteCommand(string topic)
        {
            var opportunityModelToDelete = await OpportunityModelDatabase.GetOpportunityByTopic(topic).ConfigureAwait(false);

            await OpportunityModelDatabase.DeleteItem(opportunityModelToDelete).ConfigureAwait(false);

            await TriggerPullToRefresh().ConfigureAwait(false);
        }
        public OpportunitiesViewModel()
        {
            Task.Run(async() =>
            {
                // If the database is empty, initialize the database with dummy data
                if (await OpportunityModelDatabase.GetNumberOfRowsAsync().ConfigureAwait(false) < 20)
                {
                    await InitializeDataInDatabaseAsync().ConfigureAwait(false);
                }

                await RefreshOpportunitiesDataAsync().ConfigureAwait(false);
            });
        }
예제 #3
0
        public OpportunitiesViewModel()
        {
            MessagingCenter.Subscribe <object>(this, "RefreshData", async(sender) =>
            {
                await RefreshOpportunitiesDataAsync();
            });

            Task.Run(async() =>
            {
                // If the database is empty, initialize the database with dummy data
                if (await OpportunityModelDatabase.GetNumberOfRowsAsync() < 20)
                {
                    await InitializeDataInDatabaseAsync();
                }
                await RefreshOpportunitiesDataAsync();
            });
        }
예제 #4
0
        async Task InitializeDataInDatabaseAsync(int numberOfOpportunityModelsToGenerate = 20)
        {
            for (int i = 0; i < numberOfOpportunityModelsToGenerate; i++)
            {
                var tempModel = new OpportunityModel();

                var rnd          = new Random();
                var companyIndex = rnd.Next(50);
                var dbaIndex     = rnd.Next(50);
                var leaseAmount  = rnd.Next(1000000);
                var ownerIndex   = rnd.Next(50);
                var dayIndex     = rnd.Next(1, 28);
                var monthIndex   = rnd.Next(1, 12);
                var yearIndex    = rnd.Next(2000, 2015);

                var         salesStageNumber = rnd.Next(2);
                SalesStages salesStage;
                switch (salesStageNumber)
                {
                case 0:
                    salesStage = SalesStages.New;
                    break;

                case 1:
                    salesStage = SalesStages.Pending;
                    break;

                default:
                    salesStage = SalesStages.Closed;
                    break;
                }

                tempModel.Topic       = $"{i + 715003} / Investment Data Corp";
                tempModel.Company     = $"{LoremIpsumConstants.LoremIpsum.Substring(companyIndex, 10)}";
                tempModel.DBA         = $"{LoremIpsumConstants.LoremIpsum.Substring(dbaIndex, 10)}";
                tempModel.LeaseAmount = leaseAmount;
                tempModel.SalesStage  = salesStage;
                tempModel.Owner       = $"{LoremIpsumConstants.LoremIpsum.Substring(ownerIndex, 10)}";
                tempModel.DateCreated = new DateTime(yearIndex, monthIndex, dayIndex);

                await OpportunityModelDatabase.SaveOpportunityAsync(tempModel);
            }
        }
        async void HandleDeleteActionClicked(object sender, EventArgs e)
        {
            var menuItem      = (MenuItem)sender;
            var selectedModel = menuItem.BindingContext as OpportunityModel;

            await OpportunityModelDatabase.DeleteItemAsync(selectedModel).ConfigureAwait(false);

            //Wait for the iOS animation to finish
            switch (Device.RuntimePlatform)
            {
            case Device.iOS:
                await Task.Delay(250).ConfigureAwait(false);

                break;
            }

            var navigationPage         = Application.Current.MainPage as ShakeListenerNavigationPage;
            var opportunitiesPage      = navigationPage.CurrentPage as OpportunitiesPage;
            var opportunitiesViewModel = opportunitiesPage.BindingContext as OpportunitiesViewModel;

            opportunitiesViewModel.RefreshAllDataCommand?.Execute(null);
        }
        async Task ExecuteSaveButtonTapped()
        {
            if (Topic?.Length == 0 || Company?.Length == 0 || Owner?.Length == 0 || DBA?.Length == 0 || LeaseAmount == 0)
            {
                OnSaveError();
                return;
            }

            DateCreated = DateTime.Now;
            await OpportunityModelDatabase.SaveOpportunityAsync(new OpportunityModel
            {
                Topic       = Topic,
                Company     = Company,
                DBA         = DBA,
                LeaseAmount = LeaseAmount,
                SalesStage  = SalesStage,
                Owner       = Owner,
                DateCreated = DateCreated
            });

            OnSaveToDatabaseCompleted();
        }
        public OpportunitiesViewCell()
        {
            var model = BindingContext as OpportunityModel;

            #region Create Image
            var beaconFundingImage = new Image
            {
                Source = "beaconfundingicon"
            };
            #endregion

            #region Create Topic Stack
            var topicLabel = new Label
            {
                Text           = "Topic",
                FontAttributes = FontAttributes.Bold
            };
            var topic = new Label();
            topic.SetBinding(Label.TextProperty, nameof(model.Topic));

            var topicStack = new StackLayout
            {
                Children =
                {
                    topicLabel,
                    topic
                }
            };
            #endregion

            #region Create Company
            var companyLabel = new Label
            {
                Text           = "Company",
                FontAttributes = FontAttributes.Bold
            };
            var company = new Label();
            company.SetBinding(Label.TextProperty, nameof(model.Company));

            var companyStack = new StackLayout
            {
                Children =
                {
                    companyLabel,
                    company
                }
            };
            #endregion

            #region Create LeaseAmount
            var leaseAmountLabel = new Label
            {
                Text           = "LeaseAmount",
                FontAttributes = FontAttributes.Bold
            };
            var leaseAmount = new Label();
            leaseAmount.SetBinding(Label.TextProperty, nameof(model.LeaseAmountAsCurrency));

            var leaseAmountStack = new StackLayout
            {
                Children =
                {
                    leaseAmountLabel,
                    leaseAmount
                }
            };
            #endregion

            #region Create LeaseAmount
            var ownerLabel = new Label
            {
                Text           = "Owner",
                FontAttributes = FontAttributes.Bold
            };
            var owner = new Label();
            owner.SetBinding(Label.TextProperty, nameof(model.Owner));

            var ownerStack = new StackLayout
            {
                Children =
                {
                    ownerLabel,
                    owner
                }
            };
            #endregion

            #region Create MenuItem
            var deleteAction = new MenuItem
            {
                Text          = "Delete",
                IsDestructive = true
            };

            deleteAction.Clicked += async(sender, e) =>
            {
                var menuItem = (MenuItem)sender;
                OpportunityModel thisModel = ((OpportunityModel)menuItem.BindingContext);
                await OpportunityModelDatabase.DeleteItemAsync(thisModel);

                //Wait for the iOS animation to finish
                switch (Device.RuntimePlatform)
                {
                case Device.iOS:
                    await Task.Delay(300);

                    break;
                }

                MessagingCenter.Send <object>(this, "RefreshData");
            };
            ContextActions.Add(deleteAction);
            #endregion

            StackLayout cellStack;
            #region Create Cell Horizontal StackLayout for Phone
            if (Device.Idiom == TargetIdiom.Phone)
            {
                topic.LineBreakMode = LineBreakMode.NoWrap;
                cellStack           = new StackLayout
                {
                    HorizontalOptions = LayoutOptions.Fill,
                    Padding           = 10,
                    Spacing           = 20,
                    Orientation       = StackOrientation.Horizontal,
                    Children          =
                    {
                        beaconFundingImage,
                        topicStack
                    }
                };
            }
            #endregion

            #region Create Cell Horizontal StackLayout for Tablet or Desktop
            else
            {
                cellStack = new StackLayout
                {
                    HorizontalOptions = LayoutOptions.Fill,
                    Padding           = 10,
                    Spacing           = 20,
                    Orientation       = StackOrientation.Horizontal,
                    Children          =
                    {
                        beaconFundingImage,
                        topicStack,
                        companyStack,
                        leaseAmountStack,
                        ownerStack
                    }
                };
            }
            #endregion

            View = cellStack;
        }
예제 #8
0
 public async Task RefreshOpportunitiesDataAsync()
 {
     AllOpportunitiesData = await OpportunityModelDatabase.GetAllOpportunityDataAsync_OldestToNewest();
 }