private async void Submit_OnClicked(object sender, EventArgs e)
        {
            ((Button)sender).IsEnabled = false;
            var button         = (sender as Button);
            var bindingcontext = button.BindingContext as TimeEntryListElementOverservableCollection;

            try
            {
                await RepliConnect.SubmitTimesheet(bindingcontext?.Cast <TimeEntryParent>().ToList());

                await Application.Current.MainPage.DisplayAlert("Success", "Timesheet submitted", "ok");
            }
            catch (Exception ex)
            {
                _ui.Post(
                    async(state) =>
                {
                    await Application.Current.MainPage.DisplayAlert("Attention", ex.Message, "ok");
                }, null);
            }
            finally
            {
                ((Button)sender).IsEnabled = true;
            }
        }
Esempio n. 2
0
        public static async Task <bool> LoadData(IProgress <double> progress)
        {
            //get list of all uri's on the database.
            currentURIS = App.Database.GetItems <RepliconTask>().Select(x => x.uri).ToArray();

            //update progressbar
            progress?.Report(.010);

            //load ticket from DB
            var rawData = await RepliConnect.GetTickets();

            if (rawData == null)
            {
                progress?.Report(0);
                return(false);
            }

            //update progressbar
            progress?.Report(.015);

            //cast to list to allow getting total count
            var dataList = rawData.ToList();
            //set local variable of total count
            int rawDataCount = dataList.Count;


            //counter for number of items itterated
            double totalProcessed = 0;

            foreach (var item in dataList)
            {
                //update progress
                progress?.Report(Math.Round(totalProcessed++ / rawDataCount, 3));

                //Skip item if already in DB
                if (!Predicate(item))
                {
                    continue;
                }

                //create new task
                var task = new RepliconTask();
                task.ProjectURI = item.ProjectURI;

                //assign values
                if (string.IsNullOrEmpty(item.TaskURI)) //is Project
                {
                    task.name = item.ProjectName;
                }
                else // is task
                {
                    task.description = item.TaskCode;
                    task.name        = item.TaskName;
                    task.uri         = item.TaskURI;
                }


                //set billable status
                task.IsBillable = (!string.IsNullOrEmpty(item.BillingType)) &&
                                  item.BillingType.Equals("Time And Material");

                //save to DB
                App.Database.SaveItem(task);
            }

            //update progress to 100%
            progress?.Report(1);

            //Invoke delegate for any work to be done after sync
            OnTicketLoadCompleted?.Invoke();

            return(true);
        }