Example #1
0
 public async Task UpsertRecord(ConfirmRecord confirmRecord)
 {
     if (confirmRecord.Id == null)
     {
         await confirmTable.InsertAsync(confirmRecord);
     }
     else
     {
         await confirmTable.UpdateAsync(confirmRecord);
     }
 }
Example #2
0
        public ConfirmTabbedPage()
        {
            InitializeComponent();

            _tableManager   = new ConfirmTableManager();
            _inputValidator = new InputValidator();
            confirmRecord   = new ConfirmRecord();
            campaignsList   = new List <Campaign>();
            brandsList      = new List <Brand>();


            Sync();
            OnLogRecordButtonClicked();
            BindListViewContents();

            var dependency = DependencyService.Get <IGetExternalStoragePath>();

            Debug.WriteLine("External Storage : " + dependency.GetExternalStoragePath());
        }
Example #3
0
        //public string ValidateConfirmRecord(ConfirmRecord confirmRecord)
        //{
        //    if (confirmRecord.ImageName == "")
        //        return "Please capture an Image";
        //    else if (confirmRecord.ActiveCampaign == "")
        //        return "Please select a Campaign";
        //    else if (confirmRecord.Brand1 == "" && confirmRecord.Brand2 == "" && confirmRecord.Brand3 == "")
        //        return "Please select atleast one Brand";
        //    else if (confirmRecord.StoreInformation == null)
        //        return "Please enter Store information";
        //    else
        //        return "valid";
        //}

        public List <bool> ValidationResult(ConfirmRecord confirmRecord, out bool IsValid)
        {
            List <bool> validationResult = new List <bool>(3)
            {
                false, false, false
            };

            bool[] validateResult = { false, false, false };


            Debug.WriteLine("INDEX OF ARRAY : " + validationResult.Count);
            if (!(confirmRecord.ImageName == ""))
            {
                validationResult[0] = true;
                Debug.WriteLine("Imagename : " + confirmRecord.ImageName);
                Debug.WriteLine("Imagename : " + true);
            }

            if (!(confirmRecord.Brand1 == "" && confirmRecord.Brand2 == "" && confirmRecord.Brand3 == ""))
            {
                validationResult[1] = true;
                Debug.WriteLine("Brands : " + true);
            }

            if (!(confirmRecord.StoreInformation == null) && !(confirmRecord.StoreInformation == ""))
            {
                validationResult[2] = true;
                Debug.WriteLine("Store Information : " + true);
                Debug.WriteLine("Store Information : " + confirmRecord.StoreInformation);
            }


            IsValid = IsValidConfirmRecord(validationResult);

            Debug.WriteLine("Result : " + IsValid);

            return(validationResult);
        }
Example #4
0
        private async void OnSubmitButtonClicked(object sender, EventArgs e)
        {
            double lat = 0;
            double lng = 0;

            ConfirmRecord confirmRecord = new ConfirmRecord
            {
                ActiveCampaign   = selectedCampaignID,
                Brand1           = ReturnBrandID(0, isBrand1Selected),
                Brand2           = ReturnBrandID(1, isBrand2Selected),
                Brand3           = ReturnBrandID(2, isBrand3Selected),
                StoreInformation = Name_EntryStoreInfo.Text,
                Note             = Name_EntryNote.Text,
                Latitude         = lat,
                Longitude        = lng,
                ImageName        = imageName,
                CreatedDate      = DateTime.Now.ToString("MM/dd/yyyy h:mm tt")
            };

            bool isValid = false;

            List <bool> validationResult = (_inputValidator.ValidationResult(confirmRecord, out isValid));

            DisplayAlert(validationResult);

            if (isValid)
            {
                try
                {
                    var locator = CrossGeolocator.Current;
                    if (!locator.IsGeolocationEnabled)
                    {
                        var isOpenSettingsClicked = await DisplayAlert("Alert", "GPS is disable in your device. Please enable GPS to submit record", "Go to settings", "No");

                        if (isOpenSettingsClicked)
                        {
                            var dependency = DependencyService.Get <IGPSChecker>();
                            dependency.OpenGPSSetting();
                        }
                    }
                    else if (locator.IsGeolocationEnabled)
                    {
                        Name_ProgressMessage.IsVisible = true;
                        locator.DesiredAccuracy        = 50;

                        var position = await locator.GetPositionAsync(100000);

                        if (position == null)
                        {
                            return;
                        }
                        lat = position.Latitude;
                        lng = position.Longitude;

                        confirmRecord.Latitude         = lat;
                        confirmRecord.Longitude        = lng;
                        Name_ProgressMessage.IsVisible = false;
                        await _tableManager.UpsertRecord(confirmRecord);
                        await DisplayAlert("Success", "Your response has been saved successfully", "Ok, create new response");

                        ResetUI();
                    }
                }
                catch (Exception ex)
                {
                    await DisplayAlert("Alert", "Unable to get location, Please submit record again", "Ok");

                    Debug.WriteLine("Unable to get location, may need to increase timeout: " + ex);
                }
            }
            else
            {
                // DisplayAlert(validationResult);
            }

            OnLogRecordButtonClicked();
            BindListViewContents();
        }