private async Task AddNewContactAsync()
        {
            using (CompliXperAppContext context = new CompliXperAppContext())
            {
                if (NewContact != null || firstName != null)
                {
                    NewContact.FirstName   = firstName;
                    NewContact.LastName    = lastName;
                    NewContact.Email       = newContactEmail;
                    NewContact.CreatedDate = DateTime.Now;
                    context.Add(NewContact);
                    try
                    {
                        await context.SaveChangesAsync();

                        App.Current.MainPage = new NavigationPage(new CompliXpertAppMasterDetailPage());
                        await App.Current.MainPage.Navigation.PopToRootAsync();
                    }
                    catch (DbUpdateException e)
                    {
                        SqliteException ex = (SqliteException)e.InnerException;
                        Console.WriteLine(ex.SqliteErrorCode);
                        await App.Current.MainPage.Navigation.PopToRootAsync();

                        DependencyService.Get <IToast>().WriteToast(e.InnerException.Message);
                    }
                }
            }
        }
        //adding the callreport to the table
        public async Task SaveCallReportAsync()
        {
            using (var context = new CompliXperAppContext())
            {
                context.Add <CallReport>(NewCallReport);
                await context.SaveChangesAsync();

                ////get the lastes call report
                CallReport lastReport = await context.CallReport
                                        .OrderByDescending(r => r.CallReportId)
                                        .FirstAsync();

                ////get the lastes call report

                List <CallReportResponse> responses = new List <CallReportResponse>();
                foreach (QuestionandResponse qr in QR)
                {
                    responses.Add(
                        new CallReportResponse
                    {
                        Response     = qr.Response,
                        QuestionId   = qr.QuestionId,
                        CallReportId = lastReport.CallReportId
                    }
                        );
                }
                lastReport.Responses = responses;
                //add the responses to the DB
                await context.AddRangeAsync(responses);

                await context.SaveChangesAsync();
            }
        }
Ejemplo n.º 3
0
        async Task AddProspectAsync()
        {
            //generate a prospect account number
            ProspectAccount.AccountClassCode = AccountClass.AccountClassCode;
            Prospect.CustomerName            = CustomerName;
            Prospect.Email              = prospectEmail;
            Prospect.LegalType          = LegalType;
            Prospect.CreatedOnMobile    = true;
            Prospect.Citizenship        = Citizenship?.CountryCode;
            Prospect.CountryofResidence = CountryofResidence?.CountryCode;
            Prospect.CreatedDate        = DateTime.Now;
            //add the new propsect to the DB here
            if (Prospect != null)
            {
                Random random = new Random();
                using (CompliXperAppContext context = new CompliXperAppContext())
                {
                    //get the latest Customer Number
                    int lastCustomerNumber = (int)await context.Customer
                                             .OrderByDescending(c => c.CustomerId)
                                             .Select(c => c.CustomerNumber).LastOrDefaultAsync();

                    Prospect.CustomerNumber        = random.Next(lastCustomerNumber, 999999999);
                    Prospect.CustomerId            = Prospect.CustomerNumber;
                    ProspectAccount.AccountNumber  = Prospect.CustomerNumber;
                    ProspectAccount.CustomerNumber = Prospect.CustomerNumber;
                    Prospect.Account = new List <Account>
                    {
                        ProspectAccount
                    };
                    context.Add(Prospect);
                    try
                    {
                        await context.SaveChangesAsync();

                        App.Current.MainPage = new NavigationPage(new CompliXpertAppMasterDetailPage());
                        await App.Current.MainPage.Navigation.PopToRootAsync();
                    }
                    catch (DbUpdateException e)
                    {
                        SqliteException ex = (SqliteException)e.InnerException;
                        Console.WriteLine(ex.SqliteErrorCode);
                        if (ex.SqliteErrorCode == 19)
                        {
                            //try another random number via recursion
                            await AddProspectAsync();
                        }
                    }
                }
            }
        }