public CustomerDataGather(ParentViewModel _parentVm)
        {
            InitializeComponent();           
            HeaderLabel.TextColor = Color.FromHex("5C0791");
            parentVm = _parentVm;

            //if somehow we haven't init
            if (parentVm.Customer == null)
            {
                parentVm.Customer = new CustomerViewModel();
            }

            foreach (var title in TitleList.Titles)
            {
             TitlePicker.Items.Add(title);

            }
            var possibleIndex = TitleList.Titles.ToList().FindIndex(a => a == parentVm.Customer.Title);
            var index = 0;
            if (possibleIndex != null)
            {
                index = possibleIndex;
            }

            TitlePicker.SelectedIndex = index;
            ArrowRight.Source = ImageSource.FromFile("image_arrow_right_circle");
            BindingContext = parentVm.Customer;
        }
        public WitnessesPage(ParentViewModel vm)
        {
            InitializeComponent();

            parentVm = vm;
            this.Title = "INTERRESOLVE CRASH DETECTION";
            ArrowLeft.Source = ImageSource.FromFile("image_arrow_left_circle");


            if (parentVm.Witnessses == null)
            {
                parentVm.Witnessses = new List<WitnessViewModel>();
                AddNewFakeWitness();
            }
            else
            {

            }


            /*      MessagingCenter.Subscribe<IRecordAudio, string>(this, "audioFilepath",
                      (recordAudio, audioPath) =>
                      {

                          if (!String.IsNullOrWhiteSpace(audioPath))
                          {
                              var myStream = ToStream(audioPath);

                              using (var streamReader = new StreamReader(myStream))
                              {
                                  var bytes = default(byte[]);
                                  using (var memstream = new MemoryStream())
                                  {
                                      streamReader.BaseStream.CopyTo(memstream);
                                      currentAudioRecording = memstream.ToArray();
                                  }
                              }

                          }

                      });
      */

            BindingContext = currentWitnessViewModel;
        }
        public OtherDriverPage(ParentViewModel vm)
        {
            InitializeComponent();
            parentVM = vm;
            HeaderLabel.TextColor = Color.FromHex("5C0791");
            this.BackgroundColor = Color.White;

            /*ArrowLeft.Source = ImageSource.FromFile("image_arrow_left_circle");
            ArrowRight.Source = ImageSource.FromFile("image_arrow_right_circle");

            if (parentVM.OtherDrivers == null)
            {
                vm.OtherDrivers = new OtherDriverViewModel
                {
                    Title = "Mr",
                    FirstName = "Bertie",
                    LastName = "Badman",
                    Email = "*****@*****.**",
                    Telephone = "03728 200220",
                    PolicyNumber = "VAM8asdk12D",

                };
            }
            
            BindingContext = vm.OtherDrivers;

            foreach (var title in TitleList.Titles)
            {
                TitlePicker.Items.Add(title);
            }

            TitlePicker.SelectedIndex = 1;

            foreach (var insurer in InsurerList.Insurers)
            {
                InsurerPicker.Items.Add(insurer);
            }

            InsurerPicker.SelectedIndex = 1;
            */
        }
        public AccidentDetailsPage(ParentViewModel vm)
        {
            InitializeComponent();
            parentVm = vm;
            HeaderLabel.TextColor = Color.FromHex("5C0791");
            this.BackgroundColor = Color.White;


            //if somehow we haven't init
            if (parentVm.Accident == null)
            {
                parentVm.Accident = new AccidentViewModel
                {
                    Customer = App.CurrentServerSideCustomer
                };
            }

            BindingContext = parentVm.Accident;

            ArrowLeft.Source = ImageSource.FromFile("image_arrow_left_circle");
            ArrowRight.Source = ImageSource.FromFile("image_arrow_right_circle");
            

        }
        public AccidentLocationPage(ParentViewModel _vm)
        {
            InitializeComponent();
            parentVm = _vm;
            InitalizeViewModel();


            address.Text = "No Address Yet...";
            address.HorizontalOptions = LayoutOptions.CenterAndExpand;
            latLong.Text = "No Lat/Lng Yet...";
            latLong.HorizontalOptions = LayoutOptions.CenterAndExpand;
            // The root page of your application
            map = new CustomMap
            {
                IsShowingUser = true,
                /* /* HeightRequest = 250,#1#
                  WidthRequest = 960,*/
                VerticalOptions = LayoutOptions.FillAndExpand,
                HasScrollEnabled = false,
                HorizontalOptions = LayoutOptions.FillAndExpand
            };

            var startingPosition = new Position(37.79752, -122.40183);
            map.MoveToRegion(MapSpan.FromCenterAndRadius(new Position(37.79752, -122.40183), Distance.FromMiles(0.9)));

            confirmButton = new Button();
            confirmButton.Text = "That's where my accident is!";
            confirmButton.Clicked += (sender, args) =>
            {
                //todo: //update the view model with the new co-ordinates // address and turn off location services. maybe have button to turn them back on 
                _locationConfirmed = true;
                DialogOpen();
                DisplayAlert("Thanks!", address + "", "Dismiss");
                App._locationService.StopUpdates();
                DialogClosed();
            };

            confirmButton.HorizontalOptions = LayoutOptions.FillAndExpand;

            var stack = new StackLayout { Spacing = 0, VerticalOptions = LayoutOptions.FillAndExpand, HorizontalOptions = LayoutOptions.FillAndExpand };

            stack.Children.Add(map);
            stack.Children.Add(address);
            stack.Children.Add(latLong);
           /* stack.Children.Add(confirmButton);*/
            

            Content = stack;


            MessagingCenter.Subscribe<IGetLocation, CrashLocationResult>(this, "addressExists",
               async (getLocation, s) =>
               {
                   parentVm.Accident.StreetName = s.Address.StreetName;
                   parentVm.Accident.HouseNameOrNumber = s.Address.HouseNameOrNumber;
                   parentVm.Accident.Town = s.Address.Town;
                   parentVm.Accident.Country = s.Address.Country;
                   parentVm.Accident.PostCode = s.Address.PostCode;

                   address.Text = s.AddressAsString;
                   latLong.Text = s.Lat.ToString() + "-" + s.Lng.ToString();
                   parentVm.Accident.Latitude = s.Lat;
                   parentVm.Accident.Longitude = s.Lng;
                   parentVm.Accident.AccidentDateTime = DateTime.Now;
                 

                   //Send the data we have to the API, create customer there and new customers on device. 
                   //
                   await App.CreateCustomerDeviceAndAPIIfNoKey();
                   await App.CreateAccidentDeviceAndAPIIfNoKey((DateTime)parentVm.Accident.AccidentDateTime);

                   var position = new XLabs.Platform.Services.Geolocation.Position();
                   //default position
                   position.Longitude = s.Lng;
                   position.Latitude = s.Lat;

                   var pin = new Pin
                   {
                       Type = PinType.Place,
                       Position = new Position(s.Lat, s.Lng),
                       Label = "Accident Location",
                       Address = ""
                   };

                   map.Circle = new CustomCircle
                   {
                       Position = position,
                       Radius = 800
                   };

                   map.Pins.Add(pin);

                   map.MoveToRegion(MapSpan.FromCenterAndRadius(new Position(s.Lat, s.Lng
             ), Distance.FromMiles(0.9)));


                   //save 
                   App.Context.AccidentRepository.AddOrUpdate(parentVm.Accident);
                   //update in api

                   if (!_dialogOpen)
                   {
                       if (!_locationConfirmed)
                       {
                        /*   await ConfirmLocation(s.AddressAsString);*/
                       }

                   }

               });

            /*  DisplayAlert("Hang tight, we are locating you now!", "Please wait while we search...", "Ok");*/
        }
Exemple #6
0
        private static void AssignSavedItemsIfExist(ParentViewModel parent)
        {
            var cus = Context.CustomerRepository.Get().FirstOrDefault(); //should only be 1 customer
            var accidents = Context.AccidentRepository.Get().OrderByDescending(x => x.AccidentDateTime).ToList();
            var acc = accidents.FirstOrDefault(); //get latest accident
           

            parentViewModel.Customer = cus ?? new CustomerViewModel();
            parentViewModel.Accident = acc ?? new AccidentViewModel();

            
            parentViewModel.OtherDrivers = ((OtherDriverRepository)Context.OtherDriverRepository).GetAll(acc?.Resource_uri).ToList();
            parentViewModel.Witnessses = Context.WitnessRepository.Get().ToList();
            parentViewModel.Media = Context.MediaRepository.Get().ToList();

            /*Wire up links if objects never got initialised*/
            if (String.IsNullOrEmpty(parentViewModel.Accident.Resource_uri))
            {
                parentViewModel.Accident.Customer = parentViewModel.Customer.Resource_uri;
            }

        }
Exemple #7
0
        private void InitViewModelAndAssociatedServices()
        {
            //try and get from local DB, if not create new
            parentViewModel = new ParentViewModel();

            AssignSavedItemsIfExist(parentViewModel);

            //ACCIDENT
            if (String.IsNullOrWhiteSpace(parentViewModel.Customer.Telephone))
                MessagingCenter.Subscribe<IGetPhoneNumber, string>(this, "deviceTelephone",
                  (getPhone, s) =>
                  {
                      parentViewModel.Customer.Telephone = s;


                  });


            if (String.IsNullOrWhiteSpace(parentViewModel.Customer.Email))
                MessagingCenter.Subscribe<IGetUserProfile, IEnumerable<string>>(this, "userProfiles",
                      (getUsers, userList) =>
                      {
                          parentViewModel.Customer.Email = userList.FirstOrDefault();
                      });




            //CUSTOMER
            if (String.IsNullOrWhiteSpace(parentViewModel.Customer.LastName) && (String.IsNullOrWhiteSpace(parentViewModel.Customer.FirstName)))
                MessagingCenter.Subscribe<IGetUserName, string>(this, "userName",
                  (services, s) =>
                  {
                      //
                      if (s.Contains(" "))
                      {
                          var strings = s.Split(' ');
                          parentViewModel.Customer.FirstName = strings[0];
                          parentViewModel.Customer.LastName = strings[1];
                      }
                      else
                      {
                          parentViewModel.Customer.LastName = s;
                      }
                  });


            //INIT ALL SERVICES
            //todo: only init the ones we need

            var numberService = DependencyService.Get<IGetPhoneNumber>();
            numberService.GetPhoneNumber();
            getUserNameService = DependencyService.Get<IGetUserName>();
            getUserNameService.GetUserName();
            getUserNameService = null;
            var userService = DependencyService.Get<IGetUserProfile>();
            userService.GetAllUserProfiles();


        }