private async void btnDeleteTimesheet_Clicked()
        {
            var resp = await DisplayActionSheet("Do you want to unsubmit the timesheet?", "No", "Yes");

            if (resp != null && resp.ToString().Length > 0 && resp.Equals("Yes"))
            {
                ApiDeleteResponse result = await TimeSheetService.Delete(viewModel.CurrentPeriod.TimeSheetId.Value);

                if (result != null)
                {
                    if (result.HasErrors)
                    {
                        foreach (var error in result.Errors)
                        {
                            Common.Instance.ShowToastMessage(error.ErrorMessage, DoubleResources.DangerSnackBar);
                        }
                    }
                    else
                    {
                        Common.Instance.ShowToastMessage("Timesheet deleted!", DoubleResources.SuccessSnackBar);
                        MessagingCenter.Send(this, "TimeSheetApproved", true);
                        await Navigation.PopToRootAsync();
                    }
                    //await Navigation.PopAsync();
                }
                else
                {
                    Common.Instance.ShowToastMessage("Error contacting server!", DoubleResources.DangerSnackBar);
                }
            }
        }
Beispiel #2
0
        public static void ResetTimeSheet(ProjectService projectService, TimeSheetService timeSheetService, List <TimeSheet> timeSheets = null)
        {
            var projectIds = projectService.GetIds();

            if (timeSheets.IsEmpty())
            {
                timeSheets = timeSheetService.Get();
            }

            foreach (var item in timeSheets)
            {
                if (!projectIds.Contains(item.ProjectId))
                {
                    timeSheetService.Delete(item.Id);
                }
                else
                {
                    var project = projectService.Get(item.ProjectId);

                    if (!project.IsPublic)
                    {
                        foreach (var week in item.WeekTimeSheets)
                        {
                            var taskIds = new List <int>(week.Value.Keys);
                            foreach (var taskId in taskIds)
                            {
                                if (!project.Tasks.Select(o => o.Id).Contains(taskId))
                                {
                                    week.Value.Remove(taskId);
                                }
                            }
                        }

                        timeSheetService.Update(item);
                    }
                }
            }
        }