Example #1
0
        public async Task SavePersonAsync()
        {
            using (var context = new CompliXperAppContext())
            {
                //retrieving entity by person id
                Person dbPerson = await context.Persons.SingleOrDefaultAsync(p => p.PersonId == person.PersonId);

                if (dbPerson != null)
                {
                    dbPerson.FirstName   = person.FirstName;
                    dbPerson.LastName    = person.LastName;
                    dbPerson.Email       = personEmail;
                    dbPerson.PhoneNumber = person.PhoneNumber;
                    dbPerson.Position    = person.Position;
                    dbPerson.CreatedDate = DateTime.Now;
                    context.Persons.Update(dbPerson);
                }

                try
                {
                    await context.SaveChangesAsync();
                }
                catch (DbUpdateException e)
                {
                    Console.WriteLine(e.InnerException);
                }
                await App.Current.MainPage.Navigation.PopModalAsync();

                //send person back to the list screen
                List <Person> personsList = await(from p in context.Persons
                                                  where p.CallReportId == person.CallReportId
                                                  select p).ToListAsync();
                MessagingCenter.Send <PersonDetailsScreenViewModel, List <Person> >(this, Message.PersonsLoaded, personsList);
            }
        }
        //methods
        public async Task SaveNoteAsync()
        {
            using (var context = new CompliXperAppContext())
            {
                //retrieving entity by note id
                Note dbNote = await context.Notes.SingleOrDefaultAsync(n => n.NoteId == note.NoteId);

                if (dbNote != null)
                {
                    dbNote.Subject     = note.Subject;
                    dbNote.Description = note.Description;
                    context.Notes.Update(dbNote);
                }

                try
                {
                    await context.SaveChangesAsync();
                }
                catch (DbUpdateException e)
                {
                    Console.WriteLine(e.InnerException);
                }
                await App.Current.MainPage.Navigation.PopModalAsync();

                //send person back to the list screen
                List <Note> notesList = await(from n in context.Notes
                                              where n.CallReportId == note.CallReportId
                                              select n).ToListAsync();
                MessagingCenter.Send <NoteDetailsScreenViewModel, List <Note> > (this, Message.NotesLoaded, notesList);
            }
        }
Example #3
0
        public PersonsListScreenViewModel()
        {
            AddPersonCommand = new Command(async() => await AddPersonAsync());

            MessagingCenter.Subscribe <CallReportDetailsViewModel, int>(this, Message.CallReportId, (sender, callReportId) =>
            {
                crId = callReportId;
                callReportCreatedAlready = true;
            });

            //call any DB actions here
            MessagingCenter.Subscribe <CallReportDetailsViewModel, int>(this, Message.CallReportId, async(sender, callReportId) =>
            {
                using (CompliXperAppContext context = new CompliXperAppContext())
                {
                    Persons = await(from persons in context.Persons
                                    where persons.CallReportId == callReportId
                                    select persons).ToListAsync();
                    CreatedOnMobile = await(from c in context.CallReport
                                            where c.CallReportId == callReportId
                                            select c.CreatedOnMobile).FirstOrDefaultAsync();
                    if (Persons.Count == 0)
                    {
                        PersonsCreated = false;
                    }
                    else
                    {
                        PersonsCreated = true;
                    }
                }
            });

            MessagingCenter.Subscribe <PersonDetailsScreenViewModel, List <Person> >(this, Message.PersonsLoaded, (sender, personsList) =>
            {
                if (personsList.Count == 0)
                {
                    PersonsCreated = false;
                }
                else
                {
                    PersonsCreated  = true;
                    CreatedOnMobile = personsList[0].CreatedonMobile;
                }
                Persons = personsList;
            });

            MessagingCenter.Subscribe <AddPersonScreenViewModel, Person>(this, Message.PersonCreated, (sender, person) =>
            {
                List <Person> dummyList = new List <Person>();

                foreach (Person p in Persons)
                {
                    dummyList.Add(p);
                }

                dummyList.Add(person);
                Persons        = dummyList;
                PersonsCreated = true;
            });
        }
        //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();
            }
        }
        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);
                    }
                }
            }
        }
        private async Task SaveNewContactCommandAsync()
        {
            using (CompliXperAppContext context = new CompliXperAppContext())
            {
                NewContact contact = await(from c in context.NewContacts
                                           where c.ContactId == newContact.ContactId
                                           select c).FirstOrDefaultAsync();
                if (contact != null)
                {
                    contact.Comments    = newContact.Comments;
                    contact.Company     = newContact.Company;
                    contact.CreatedDate = DateTime.Now;
                    contact.Email       = newContactEmail;
                    contact.FirstName   = newContact.FirstName;
                    contact.LastName    = newContact.LastName;
                    contact.Phonenumber = newContact.Phonenumber;
                    contact.Title       = newContact.Title;
                    context.NewContacts.Update(contact);

                    try
                    {
                        await context.SaveChangesAsync();
                    }
                    catch (DbUpdateException e)
                    {
                        Console.WriteLine(e.InnerException);
                    }
                    await App.Current.MainPage.Navigation.PopToRootAsync();
                }
            }
        }
        private void InitializeCallReportQuestions()
        {
            using (CompliXperAppContext context = new CompliXperAppContext())
            {
                Questions = (
                    from q in context.CallReportQuestions
                    where q.Type == Type.Type
                    select new CallReportQuestions
                {
                    QuestionId = q.QuestionId,
                    QuestionHeader = q.QuestionHeader,
                    Status = q.Status,
                    Type = q.Type
                }
                    ).ToList();

                //add to qr

                List <QuestionandResponse> ques = new List <QuestionandResponse>();
                foreach (CallReportQuestions question in Questions)
                {
                    QuestionandResponse qr = new QuestionandResponse();
                    qr.QuestionHeader = question.QuestionHeader;
                    qr.QuestionId     = question.QuestionId;
                    qr.Response       = "";
                    ques.Add(qr);
                }
                QR = ques;
            }
        }
        //methods
        public async Task DBContainsRecords()
        {
            using (CompliXperAppContext context = new CompliXperAppContext())
            {
                //IsBusy = true;
                if (context.Customer.Any() == true)
                {
                    await App.Current.MainPage.Navigation.PushAsync(new CompliXpertAppMasterDetailPage());

                    App.Current.MainPage = new NavigationPage(new CompliXpertAppMasterDetailPage());
                    IsBusy = false;
                }
                else
                {
                    //make a call to the Api
                    bool result = await PopulateSqliteDb();

                    if (result == true)
                    {
                        //the Customer List screen is set as the root page.
                        await App.Current.MainPage.Navigation.PushAsync(new CompliXpertAppMasterDetailPage());

                        App.Current.MainPage = new NavigationPage(new CompliXpertAppMasterDetailPage());
                        IsBusy = false;
                    }
                }
            }
        }
 //methods
 public async void InitializeData()
 {
     using (var context = new CompliXperAppContext())
     {
         //get all callreport types
         CallReportTypes = await context.CallReportType.ToListAsync();
     }
 }
 private async void InitializeCreateCallReportScreenAsync()
 {
     using (CompliXperAppContext context = new CompliXperAppContext())
     {
         CustomerName = await(
             from c in context.Customer
             where c.CustomerNumber == Account.CustomerNumber
             select c.CustomerName
             ).FirstOrDefaultAsync();
     }
 }
        public async Task <bool> PopulateSqliteDb()
        {
            using (CompliXperAppContext context = new CompliXperAppContext())
            {
                Task <Account[]>             accounts            = GetAccountsAsync();
                Task <ProductCode[]>         productCodes        = GetProductCodesAsync();
                Task <AccountClass[]>        accountClasses      = GetAccountClassesAsync();
                Task <CallReport[]>          callReports         = GetCallReportsAsync();
                Task <CallReportQuestions[]> callReportQuestions = GetCallReportQuestionsAsync();
                Task <CallReportType[]>      callReportTypes     = GetCallReportTypesAsync();
                Task <Country[]>             countries           = GetCountriesAsync();
                Task <Customer[]>            customers           = GetCustomersAsync();
                Task <IndustryType[]>        industryTypes       = GetIndustryTypesAsync();
                Task <LinesofBusiness[]>     linesofBusinesses   = GetLinesofBusinessAsync();
                Task <CallReportResponse[]>  responses           = GetCallReportResponsesAsync();

                //awaiting each task
                try
                {
                    context.AddRange(await accounts);
                    context.AddRange(await productCodes);
                    context.AddRange(await accountClasses);
                    context.AddRange(await callReports);
                    context.AddRange(await callReportQuestions);
                    context.AddRange(await callReportTypes);
                    context.AddRange(await countries);
                    context.AddRange(await customers);
                    context.AddRange(await industryTypes);
                    context.AddRange(await linesofBusinesses);
                    context.AddRange(await responses);
                }
                catch (Exception)
                {
                    await App.Current.MainPage.DisplayAlert("Something went wrong.", "It appears you are not connected to the internet.", "OK");

                    await App.Current.MainPage.Navigation.PopAsync();

                    return(false);
                }
                try
                {
                    await context.SaveChangesAsync();

                    return(true);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.InnerException);
                    return(false);
                }
            }
        }
Example #12
0
 public void InitializeData()
 {
     //check to see if there are any prospects that have been created
     using (CompliXperAppContext context = new CompliXperAppContext())
     {
         ProspectList = (from prospect in context.Customer
                         where prospect.CreatedOnMobile == true
                         select new Customer()
         {
             Account = (from account in context.Account
                        where account.CustomerNumber == prospect.CustomerNumber
                        select new Account()
             {
                 AccountClassCode = account.AccountClassCode,
                 AccountNumber = account.AccountNumber,
                 AccountType = account.AccountType,
                 BusinessCode = account.BusinessCode,
                 CustomerNumber = account.CustomerNumber,
                 CustomerNumberNavigation = account.CustomerNumberNavigation,
                 IndustryCode = account.IndustryCode,
                 ProductCode = account.ProductCode,
                 CallReport = (from callReport in context.CallReport
                               where callReport.AccountNumber == account.AccountNumber
                               select callReport).ToList(),
                 AccountClass = (from accountClass in context.AccountClasses
                                 where accountClass.AccountClassCode == account.AccountClassCode
                                 select accountClass).FirstOrDefault(),
             }).ToList(),
             BusinessCode = prospect.BusinessCode,
             Citizenship = prospect.Citizenship,
             CountryofResidence = prospect.CountryofResidence,
             CreatedDate = prospect.CreatedDate,
             CreatedOnMobile = prospect.CreatedOnMobile,
             CustomerId = prospect.CustomerId,
             CustomerName = prospect.CustomerName,
             CustomerNumber = prospect.CustomerNumber,
             Email = prospect.Email,
             IndustryCode = prospect.IndustryCode,
             IsPEP = prospect.IsPEP,
             LegalType = prospect.LegalType,
             MailAddress = prospect.MailAddress
         }).ToList();
     }
     if (_prospectList.Count == 0)
     {
         ProspectsCreated = false;
     }
     else
     {
         ProspectsCreated = true;
     }
 }
Example #13
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();
                        }
                    }
                }
            }
        }
Example #14
0
        //download all the new data that has been added...phase 1(just new Call Reports)
        //will become a Http Push request
        public async Task DownloadCallReportsAsync()
        {
            //ask the user if he wants to download
            if (await App.Current.MainPage.DisplayAlert("Downloading all New Data will remove the data from the CompliXpert App.", "This action cannot be undone.", "Yes", "Cancel"))
            {
                IsBusy = true;
                using (var context = new CompliXperAppContext())
                {
                    //get all the Call Reports in the system that were created on the mobile device
                    var callReports = await context.CallReport
                                      .Where(report => report.CreatedOnMobile == true)
                                      .ToListAsync();

                    //then get all the accounts formed associated with the newly created Call Reports
                    List <Account> accounts = new List <Account>();
                    foreach (CallReport report in callReports)
                    {
                        Account account = await(from _account in context.Account
                                                where _account.AccountNumber == report.AccountNumber
                                                select new Account
                        {
                            AccountNumber    = _account.AccountNumber,
                            AccountType      = _account.AccountType,
                            AccountClassCode = _account.AccountClassCode,
                            CustomerNumber   = _account.CustomerNumber,
                        }).FirstOrDefaultAsync();

                        account.CallReport.Add(report);
                        //accounts.Add(await context.Account
                        //    .Where(account => account.AccountNumber == report.AccountNumber)
                        //    .FirstOrDefaultAsync());
                    }

                    //get the customers associated with those accounts


                    //make into a Json variable
                    string callReportsJson = JsonConvert.SerializeObject(callReports);

                    //save the json to text file for testing purposes
                    JsonConvert.DeserializeObject <List <Customer> >(await DependencyService.Get <IRWExternalStorage>().ReadFileAsync());
                    await DependencyService.Get <IRWExternalStorage>().WriteFileAsync(callReportsJson);

                    IsBusy = false;
                    //drop all data from the sqlite database
                    //context.Account.RemoveRange(context.Account.ToArray());
                }
            }
        }
Example #15
0
 //constructor
 public AddProspectScreenViewModel()
 {
     TextEntered        = false;
     EmailValidated     = false;
     AddProspectCommand = new Command(async() => await AddProspectAsync(), () => canAdd);
     AccountClass       = new AccountClass();
     Prospect           = new Customer();
     ProspectAccount    = new Account();
     //get a list of countries && account class
     using (var context = new CompliXperAppContext())
     {
         Countries      = context.Countries.ToList();
         AccountClasses = context.AccountClasses.ToList();
     }
 }
        public async void InitializeData()
        {
            IsBusy = true;
            using (CompliXperAppContext context = new CompliXperAppContext())
            {
                ContactsList = await context.NewContacts.ToListAsync();

                if (contactsList.Count > 0)
                {
                    ContactsCreated = true;
                }
                else
                {
                    ContactsCreated = false;
                }
            }
            IsBusy = false;
        }
Example #17
0
        //remove Call Report from local DB
        public async Task DeleteCallReportAsync()
        {
            if (await App.Current.MainPage.DisplayAlert("Are you sure you want to delete this Call Report?", "This action cannot be undone.", "Yes", "Cancel"))
            {
                using (var context = new CompliXperAppContext())
                {
                    IsBusy = true;
                    var entity = await context.CallReport.FirstOrDefaultAsync(x => x.CallReportId == Report.CallReportId);

                    context.CallReport.Remove(entity);
                    await context.SaveChangesAsync();

                    IsBusy = false;
                    await App.Current.MainPage.Navigation.PopAsync();

                    MessagingCenter.Send <CallReportDetailsViewModel, int?>(this, Message.AccountNumber, Report.AccountNumber);
                }
            }
        }
Example #18
0
        //really an update call report
        public async Task SaveCallReportAsync()
        {
            using (var context = new CompliXperAppContext())
            {
                IsBusy = true;
                //retrieving entity by id
                CallReport report = await context.CallReport
                                    .SingleAsync(r => r.CallReportId == Report.CallReportId);

                report.CallDate    = Report.CallDate;
                report.CreatedDate = DateTime.Now;
                report.Position    = Report.Position;
                report.Reference   = Report.Reference;
                List <CallReportResponse> responses = new List <CallReportResponse>();
                foreach (var qr in QuestionandResponses)
                {
                    responses.Add(
                        new CallReportResponse
                    {
                        Response     = qr.Response,
                        QuestionId   = qr.QuestionId,
                        CallReportId = report.CallReportId,
                        ResponseId   = qr.ResponseId
                    }
                        );
                }
                context.CallReportResponse.UpdateRange(responses);

                try
                {
                    await context.SaveChangesAsync();
                }
                catch (DbUpdateException e)
                {
                    Console.WriteLine(e.InnerException);
                }

                IsBusy = false;
                await App.Current.MainPage.Navigation.PopToRootAsync();

                MessagingCenter.Send <CallReportDetailsViewModel, int?>(this, Message.AccountNumber, Report.AccountNumber);
            }
        }
 //constructor
 public CallReportListViewModel()
 {
     MessagingCenter.Subscribe <CustomerMasterViewModel, int>(this, Message.AccountNumber, async(sender, acctNumber) =>
     {
         using (var context = new CompliXperAppContext())
         {
             CallReports = context.CallReport.Where(report => report.AccountNumber == acctNumber).ToList();
             foreach (CallReport report in _callReportsList)
             {
                 report.Reason    = "Type: " + report.Reason;
                 report.Responses = await(from _responses in context.CallReportResponse
                                          where _responses.CallReportId == report.CallReportId
                                          select new CallReportResponse
                 {
                     ResponseId   = _responses.ResponseId,
                     Response     = _responses.Response,
                     QuestionId   = _responses.QuestionId,
                     CallReportId = _responses.CallReportId
                 }).ToListAsync();
             }
         }
     });
     MessagingCenter.Subscribe <CallReportDetailsViewModel, int?>(this, Message.AccountNumber, async(sender, acctNumber) =>
     {
         using (var context = new CompliXperAppContext())
         {
             CallReports = context.CallReport.Where(report => report.AccountNumber == acctNumber).ToList();
             foreach (CallReport report in _callReportsList)
             {
                 report.Reason    = "Type: " + report.Reason;
                 report.Responses = await(from _responses in context.CallReportResponse
                                          where _responses.CallReportId == report.CallReportId
                                          select new CallReportResponse
                 {
                     ResponseId   = _responses.ResponseId,
                     Response     = _responses.Response,
                     QuestionId   = _responses.QuestionId,
                     CallReportId = _responses.CallReportId
                 }).ToListAsync();
             }
         }
     });
 }
        public void InitializeData()
        {
            using (CompliXperAppContext context = new CompliXperAppContext())
            {
                //gets all the customers in the DB
                List <Customer> customerList = context.Customer.ToList();

                //get only call reports that are created on mobile and initialize type correctly
                List <CallReport> callReportList = (from callreport in context.CallReport
                                                    where callreport.CreatedOnMobile == true
                                                    select new CallReport
                {
                    AccountNumber = callreport.AccountNumber,
                    CallReportId = callreport.CallReportId,
                    CallReportType = (from callreporttype in context.CallReportType
                                      where callreporttype.Type == callreport.CallReportType
                                      select callreporttype.Description).FirstOrDefault(),
                    CallDate = callreport.CallDate
                }).ToList();

                customers   = new List <CompliXpertAppMasterDetailPageMenuItem>();
                callReports = new List <CompliXpertAppMasterDetailPageMenuItem>();

                foreach (Customer customer in customerList)
                {
                    customers.Add(new CompliXpertAppMasterDetailPageMenuItem {
                        Id = customer.CustomerNumber, Title = customer.CustomerName, TargetType = typeof(SelectAccountforCallReport), Color = "#a1a1a1"
                    });
                }

                foreach (CallReport callReport in callReportList)
                {
                    string customername = (from customer in context.Customer
                                           where customer.CustomerNumber == (from account in context.Account
                                                                             where account.AccountNumber == callReport.AccountNumber
                                                                             select account.CustomerNumber).FirstOrDefault()
                                           select customer.CustomerName).FirstOrDefault();
                    callReports.Add(new CompliXpertAppMasterDetailPageMenuItem {
                        Id = callReport.CallReportId, Title = customername + ": " + callReport.CallReportType + " created " + callReport.Date, TargetType = typeof(CallReportDetailsScreen), Color = "#a1a1a1"
                    });
                }
            }
        }
Example #21
0
        //methods
        public void InitializeData()
        {
            using (CompliXperAppContext context = new CompliXperAppContext())
            {
                //initialize callreporttype list
                callReportTypes = context.CallReportType.ToList();

                var newList = new List <CallReportList>();
                //get each customer
                foreach (Customer customer in context.Customer)
                {
                    CallReportList dummyCallReportList = new CallReportList();
                    dummyCallReportList.Heading = customer.CustomerName;

                    //get all accounts
                    List <Account> accounts = (from account in context.Account
                                               where account.CustomerNumber == customer.CustomerNumber
                                               select account).ToList();
                    foreach (Account account in accounts)
                    {
                        //get the list of call reports
                        IEnumerable <CallReport> callReports = (from callreport in context.CallReport
                                                                where callreport.AccountNumber == account.AccountNumber
                                                                orderby callreport.CallDate descending
                                                                select callreport).ToList();

                        foreach (CallReport callreport in callReports)
                        {
                            callreport.Reason    = "Type: " + callreport.Reason;
                            callreport.Responses = (from response in context.CallReportResponse
                                                    where response.CallReportId == callreport.CallReportId
                                                    select response).ToList();
                        }
                        dummyCallReportList.AddRange(callReports);
                    }

                    newList.Add(dummyCallReportList);
                }

                CallReportGroup = newList;
            }
        }
        public SelectAccountforCallReportViewModel()
        {
            _canCreateCallReport = false;

            MessagingCenter.Subscribe <CompliXpertAppMasterDetailPageMasterViewModel, int>(this, Message.CustomerIdAttached, (sender, customerNumber) =>
            {
                using (CompliXperAppContext context = new CompliXperAppContext())
                {
                    _accounts = (from _account in context.Account
                                 where _account.CustomerNumber == customerNumber
                                 select _account).ToList();

                    //get all callreport types
                    CallReportTypes = context.CallReportType.ToList();
                }
                Accounts = _accounts;
            });

            CreateCallReportCommand = new Command(async() => await CreateCallReportAsync(), () => _canCreateCallReport);
        }
        async Task SavePersonAsync()
        {
            Person person = new Person()
            {
                CallReportId    = callreportId,
                CreatedDate     = DateTime.Now,
                CreatedonMobile = true,
                Email           = personEmail,
                FirstName       = firstName,
                LastName        = lastName,
                PhoneNumber     = PhoneNumber,
                Position        = Position
            };

            if (callReportCreatedAlready == true)
            {
                using (CompliXperAppContext context = new CompliXperAppContext())
                {
                    context.Persons.Add(person);

                    try
                    {
                        await context.SaveChangesAsync();

                        await App.Current.MainPage.Navigation.PopModalAsync();

                        MessagingCenter.Send <AddPersonScreenViewModel, Person>(this, Message.PersonCreated, person);
                    }
                    catch (Exception ex)
                    {
                    }
                }
            }
            else
            {
                await App.Current.MainPage.Navigation.PopModalAsync();

                ////use messaging center to send person back
                MessagingCenter.Send <AddPersonScreenViewModel, Person>(this, Message.PersonCreated, person);
            }
        }
Example #24
0
        public async Task DeletePersonAsync()
        {
            if (await App.Current.MainPage.DisplayAlert("Are you sure you want to delete this Person?", "This action cannot be undone.", "Yes", "Cancel"))
            {
                using (var context = new CompliXperAppContext())
                {
                    var entity = await context.Persons.FirstOrDefaultAsync(x => x.PersonId == person.PersonId);

                    context.Persons.Remove(entity);
                    await context.SaveChangesAsync();

                    //get current list
                    List <Person> p = (from persons in context.Persons
                                       where persons.CallReportId == person.CallReportId
                                       select persons).ToList();
                    await App.Current.MainPage.Navigation.PopModalAsync();

                    MessagingCenter.Send <PersonDetailsScreenViewModel, List <Person> >(this, Message.PersonsLoaded, p);
                }
            }
        }
        //methods
        async Task SaveNoteAsync()
        {
            Note note = new Note()
            {
                Subject         = subject,
                Description     = description,
                CreatedDate     = DateTime.Now,
                CreatedonMobile = true
            };

            if (callReportCreatedAlready == true)
            {
                using (CompliXperAppContext context = new CompliXperAppContext())
                {
                    note.CallReportId = callreportId;

                    context.Notes.Add(note);

                    try
                    {
                        await context.SaveChangesAsync();

                        await App.Current.MainPage.Navigation.PopModalAsync();

                        //message being set back to the Notes List Screen to update it
                        MessagingCenter.Send <AddNoteScreenViewModel, Note>(this, Message.NoteCreated, note);
                    }
                    catch (Exception ex)
                    {
                    }
                }
            }
            else
            {
                await App.Current.MainPage.Navigation.PopModalAsync();

                ////use messaging center to send note back
                MessagingCenter.Send <AddNoteScreenViewModel, Note>(this, Message.NoteCreated, note);
            }
        }
        //remove Call Report from local DB
        public async Task DeleteNoteAsync()
        {
            if (await App.Current.MainPage.DisplayAlert("Are you sure you want to delete this Note?", "This action cannot be undone.", "Yes", "Cancel"))
            {
                using (var context = new CompliXperAppContext())
                {
                    var entity = await context.Notes.FirstOrDefaultAsync(x => x.NoteId == Note.NoteId);

                    context.Notes.Remove(entity);
                    await context.SaveChangesAsync();

                    //get cleaned up list
                    List <Note> notes = await(from n in context.Notes
                                              where n.CallReportId == Note.CallReportId
                                              select n).ToListAsync();
                    await App.Current.MainPage.Navigation.PopModalAsync();

                    MessagingCenter.Send <NoteDetailsScreenViewModel, List <Note> >(this, Message.NotesLoaded, notes);
                    //send a message to call report details screen to make a new call
                }
            }
        }
Example #27
0
        //will check to see if new call reports were created or a prospect
        public void CheckForNewData()
        {
            using (var context = new CompliXperAppContext())
            {
                //get all the Call Reports in the system that were created on the mobile device
                var callReports = context.CallReport
                                  .Where(report => report.CreatedOnMobile == true)
                                  .ToList();
                //get all Customers that were created on the mobile devices
                var prospectList = context.Customer
                                   .Where(customer => customer.CreatedOnMobile == true)
                                   .ToList();
                if (prospectList.Count > 0)
                {
                    ProspectCreated = true;
                    CanDownload(true);
                }

                if (_newContactList.Count > 0)
                {
                    NewContactAdded = true;
                    CanDownload(true);
                }

                if (callReports.Count > 0)
                {
                    CanDownload(true);
                    CreatedOnMobile = true;
                }
                else
                {
                    CanDownload(false);
                    CreatedOnMobile = false;
                }
            }
        }
        private void Subscribe()
        {
            MessagingCenter.Subscribe <CallReportDetailsViewModel, int>(this, Message.CallReportId, (sender, callReportId) =>
            {
                crId = callReportId;
                callReportCreatedAlready = true;
            });

            MessagingCenter.Subscribe <CallReportDetailsViewModel, int>(this, Message.CallReportId, async(sender, callReportId) =>
            {
                using (CompliXperAppContext context = new CompliXperAppContext())
                {
                    IsBusy = true;
                    Notes  = await(from notes in context.Notes
                                   where notes.CallReportId == callReportId
                                   select notes).ToListAsync();
                    CreatedOnMobile = await(from c in context.CallReport
                                            where c.CallReportId == callReportId
                                            select c.CreatedOnMobile).FirstOrDefaultAsync();
                    if (Notes.Count == 0)
                    {
                        NotesCreated = false;
                    }
                    else
                    {
                        NotesCreated = true;
                    }
                    IsBusy = false;
                }
            });

            MessagingCenter.Subscribe <NoteDetailsScreenViewModel, List <Note> >(this, Message.NotesLoaded, (sender, notesList) =>
            {
                if (notesList.Count == 0)
                {
                    NotesCreated = false;
                }
                else
                {
                    NotesCreated    = true;
                    CreatedOnMobile = notesList[0].CreatedonMobile;
                }
                Notes = notesList;
            });
            MessagingCenter.Subscribe <AddNoteScreenViewModel, Note>(this, Message.NoteCreated, (sender, note) =>
            {
                List <Note> dummyList = new List <Note>();

                foreach (Note n in Notes)
                {
                    dummyList.Add(n);
                }

                dummyList.Add(note);
                Notes = dummyList;
                if (Notes.Count == 0)
                {
                    NotesCreated = false;
                }
                else
                {
                    NotesCreated = true;
                }
            });
        }
Example #29
0
        public void Subscribe()
        {
            MessagingCenter.Subscribe <CallReportListScreenViewModel, CallReport>(this, Message.CallReportLoaded, async(sender, _report) =>
            {
                Report          = _report;
                CreatedOnMobile = Report.CreatedOnMobile;

                //get the questions
                using (var context = new CompliXperAppContext())
                {
                    ReportType = await(from r in context.CallReportType
                                       where r.Type == Report.CallReportType
                                       select r.Description).SingleOrDefaultAsync();

                    Report.Notes = await(from notes in context.Notes
                                         where notes.CallReportId == Report.CallReportId
                                         select notes).ToListAsync();

                    List <CallReportQuestions> Questions = await(
                        from _q in context.CallReportQuestions
                        where _q.Type == Report.CallReportType
                        select new CallReportQuestions
                    {
                        QuestionId     = _q.QuestionId,
                        QuestionHeader = _q.QuestionHeader,
                        Status         = _q.Status,
                        Type           = _q.Type
                    }
                        ).ToListAsync();
                    List <QuestionandResponse> _qr = new List <QuestionandResponse>();
                    foreach (var question in Questions)
                    {
                        foreach (var response in Report.Responses)
                        {
                            if (question.QuestionId == response.QuestionId)
                            {
                                //instantiate new object
                                QuestionandResponse questionandResponse = new QuestionandResponse();
                                questionandResponse.QuestionHeader      = question.QuestionHeader;
                                questionandResponse.Response            = response.Response;
                                questionandResponse.QuestionId          = response.QuestionId;
                                questionandResponse.ResponseId          = response.ResponseId;
                                _qr.Add(questionandResponse);
                                break;
                            }
                        }
                    }
                    QuestionandResponses = _qr;
                }
                //manipulate the stack
                List <Page> stackPages = new List <Page>();
                foreach (Page page in App.Current.MainPage.Navigation.NavigationStack)
                {
                    stackPages.Add(page);
                }
                App.Current.MainPage.Navigation.RemovePage(App.Current.MainPage.Navigation.NavigationStack[App.Current.MainPage.Navigation.NavigationStack.Count - 2]);
                //place the new page into stack
                App.Current.MainPage.Navigation.InsertPageBefore(new CompliXpertAppMasterDetailPage()
                {
                    Detail = new NavigationPage(new CallReportsList())
                }, App.Current.MainPage.Navigation.NavigationStack[App.Current.MainPage.Navigation.NavigationStack.Count - 1]);
                MessagingCenter.Send <CallReportDetailsViewModel, int?>(this, Message.AccountNumber, Report.AccountNumber);
            });

            MessagingCenter.Subscribe <CallReportListViewModel, CallReport>(this, Message.CallReportLoaded, async(sender, _report) =>
            {
                Report          = _report;
                CreatedOnMobile = Report.CreatedOnMobile;

                //get the questions
                using (var context = new CompliXperAppContext())
                {
                    ReportType = await(from r in context.CallReportType
                                       where r.Type == Report.CallReportType
                                       select r.Description).SingleOrDefaultAsync();

                    Report.Notes = await(from notes in context.Notes
                                         where notes.CallReportId == Report.CallReportId
                                         select notes).ToListAsync();

                    List <CallReportQuestions> Questions = await(
                        from _q in context.CallReportQuestions
                        where _q.Type == Report.CallReportType
                        select new CallReportQuestions
                    {
                        QuestionId     = _q.QuestionId,
                        QuestionHeader = _q.QuestionHeader,
                        Status         = _q.Status,
                        Type           = _q.Type
                    }
                        ).ToListAsync();

                    List <QuestionandResponse> _qr = new List <QuestionandResponse>();

                    foreach (var question in Questions)
                    {
                        foreach (var response in Report.Responses)
                        {
                            if (question.QuestionId == response.QuestionId)
                            {
                                //instantiate new object
                                QuestionandResponse questionandResponse = new QuestionandResponse();
                                questionandResponse.QuestionHeader      = question.QuestionHeader;
                                questionandResponse.Response            = response.Response;
                                questionandResponse.QuestionId          = response.QuestionId;
                                questionandResponse.ResponseId          = response.ResponseId;
                                _qr.Add(questionandResponse);
                                break;
                            }
                        }
                    }
                    QuestionandResponses = _qr;
                }
                //manipulate the stack
                List <Page> stackPages = new List <Page>();
                foreach (Page page in App.Current.MainPage.Navigation.NavigationStack)
                {
                    stackPages.Add(page);
                }
                App.Current.MainPage.Navigation.RemovePage(App.Current.MainPage.Navigation.NavigationStack[App.Current.MainPage.Navigation.NavigationStack.Count - 2]);
                //place the new page into stack
                App.Current.MainPage.Navigation.InsertPageBefore(new CompliXpertAppMasterDetailPage()
                {
                    Detail = new NavigationPage(new CallReportsList())
                }, App.Current.MainPage.Navigation.NavigationStack[App.Current.MainPage.Navigation.NavigationStack.Count - 1]);
                MessagingCenter.Send <CallReportDetailsViewModel, int?>(this, Message.AccountNumber, Report.AccountNumber);
            });
            MessagingCenter.Subscribe <CompliXpertAppMasterDetailPageMasterViewModel, CallReport>(this, Message.CallReportLoaded, async(sender, _report) =>
            {
                Report          = _report;
                CreatedOnMobile = Report.CreatedOnMobile;

                //get the questions
                using (var context = new CompliXperAppContext())
                {
                    ReportType = await(from r in context.CallReportType
                                       where r.Type == Report.CallReportType
                                       select r.Description).SingleOrDefaultAsync();

                    Report.Notes = await(from notes in context.Notes
                                         where notes.CallReportId == Report.CallReportId
                                         select notes).ToListAsync();

                    List <CallReportQuestions> Questions = await(
                        from _q in context.CallReportQuestions
                        where _q.Type == Report.CallReportType
                        select new CallReportQuestions
                    {
                        QuestionId     = _q.QuestionId,
                        QuestionHeader = _q.QuestionHeader,
                        Status         = _q.Status,
                        Type           = _q.Type
                    }
                        ).ToListAsync();

                    List <QuestionandResponse> _qr = new List <QuestionandResponse>();

                    foreach (var question in Questions)
                    {
                        foreach (var response in Report.Responses)
                        {
                            if (question.QuestionId == response.QuestionId)
                            {
                                //instantiate new object
                                QuestionandResponse questionandResponse = new QuestionandResponse();
                                questionandResponse.QuestionHeader      = question.QuestionHeader;
                                questionandResponse.Response            = response.Response;
                                questionandResponse.QuestionId          = response.QuestionId;
                                questionandResponse.ResponseId          = response.ResponseId;
                                _qr.Add(questionandResponse);
                                break;
                            }
                        }
                    }
                    QuestionandResponses = _qr;
                }
                //manipulate the stack
                List <Page> stackPages = new List <Page>();
                foreach (Page page in App.Current.MainPage.Navigation.NavigationStack)
                {
                    stackPages.Add(page);
                }
                App.Current.MainPage.Navigation.RemovePage(App.Current.MainPage.Navigation.NavigationStack[App.Current.MainPage.Navigation.NavigationStack.Count - 2]);
                //place the new page into stack
                App.Current.MainPage.Navigation.InsertPageBefore(new CompliXpertAppMasterDetailPage()
                {
                    Detail = new NavigationPage(new CallReportsList())
                }, App.Current.MainPage.Navigation.NavigationStack[App.Current.MainPage.Navigation.NavigationStack.Count - 1]);
                MessagingCenter.Send <CallReportDetailsViewModel, int?>(this, Message.AccountNumber, Report.AccountNumber);
            });
        }
        private async void CallScreen(CompliXpertAppMasterDetailPageMenuItem menuItem)
        {
            MenuItem = null;
            var page = (Page)Activator.CreateInstance(menuItem.TargetType);

            if (menuItem.TargetType.FullName.Equals(typeof(CustomerListScreen).FullName))
            {
                App.Current.MainPage = new NavigationPage(new CompliXpertAppMasterDetailPage());
                await App.Current.MainPage.Navigation.PopToRootAsync();
            }
            else if (menuItem.TargetType.FullName.Equals(typeof(CreateCallReportScreen).FullName) == true || menuItem.TargetType.FullName.Equals(typeof(LoadingScreen).FullName) == true)
            {
                return;
            }
            //check target type for selectaccountforcallreport
            else if (menuItem.TargetType.FullName.Equals(typeof(SelectAccountforCallReport).FullName))
            {
                await App.Current.MainPage.Navigation.PushAsync(new CompliXpertAppMasterDetailPage()
                {
                    Detail = new NavigationPage(page)
                });

                //use messaging center here to send the customer for CreateCallReport
                MessagingCenter.Send <CompliXpertAppMasterDetailPageMasterViewModel, int>(this, Message.CustomerIdAttached, menuItem.Id);
            }
            //check to see if a note or attendee wants to be added
            else if (menuItem.TargetType.FullName.Equals(typeof(CallReportDetailsScreen).FullName))
            {
                using (CompliXperAppContext context = new CompliXperAppContext())
                {
                    CallReport callReport = (from callreport in context.CallReport
                                             where callreport.CallReportId == menuItem.Id
                                             select new CallReport
                    {
                        AccountNumber = callreport.AccountNumber,
                        AccountNumberNavigation = callreport.AccountNumberNavigation,
                        ApprovedBy = callreport.ApprovedBy,
                        ApprovedDate = callreport.ApprovedDate,
                        CallDate = callreport.CallDate,
                        CallReportId = callreport.CallReportId,
                        CallReportType = callreport.CallReportType,
                        CreatedOnMobile = callreport.CreatedOnMobile,
                        LastUpdated = callreport.LastUpdated,
                        LastUpdatedDate = callreport.LastUpdatedDate,
                        Notes = (from notes in context.Notes
                                 where notes.NoteId == callreport.CallReportId
                                 select notes).ToList(),
                        Officer = callreport.Officer,
                        Position = callreport.Position,
                        Reason = callreport.Reason,
                        Reference = callreport.Reference,
                        Responses = (from responses in context.CallReportResponse
                                     where responses.CallReportId == callreport.CallReportId
                                     select responses).ToList()
                    }).FirstOrDefault();

                    await App.Current.MainPage.Navigation.PushAsync(new CompliXpertAppMasterDetailPage()
                    {
                        Detail = new NavigationPage(page)
                    });

                    //use messaging center here to send the customer for CreateCallReport
                    MessagingCenter.Send <CompliXpertAppMasterDetailPageMasterViewModel, CallReport>(this, Message.CallReportLoaded, callReport);
                }
            }
            //this is the condition for any other menu choice
            else
            {
                await App.Current.MainPage.Navigation.PushAsync(new CompliXpertAppMasterDetailPage()
                {
                    Detail = new NavigationPage(page)
                });
            }
        }