示例#1
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 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();
        }