Exemplo n.º 1
0
        public async Task ExecuteLoadItemsCommand()
        {
            IsBusy = true;

            try
            {
                Items.Clear();

                var request = new Model.Requests.TimeSheetSearchRequest
                {
                    Month = SelectedMonth?.Id ?? DateTime.Today.Month,
                    Year  = SelectedYear?.Id ?? DateTime.Today.Year
                };
                var items = await _serviceTimeSheets.Get <List <Model.DTO.TimeSheetDTO> >(request);

                Items.Clear();
                foreach (var item in items)
                {
                    Items.Add(item);
                }
            }
            catch (FlurlHttpException ex)
            {
                var responseBody = await ex.GetResponseStringAsync();

                Debug.WriteLine(responseBody);
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex);
            }
            finally
            {
                IsBusy = false;
            }
        }
Exemplo n.º 2
0
 public ActionResult <List <Model.DTO.TimeSheetDTO> > GetTimeSheets([FromQuery] Model.Requests.TimeSheetSearchRequest request)
 {
     return(_TimeSheetsService.GetTimeSheets(request));
 }
Exemplo n.º 3
0
        private async Task ExecuteApproveCloseCommand()
        {
            var      today           = DateTime.Today;
            int      daysInMonth     = DateTime.DaysInMonth(SelectedYear.Id, SelectedMonth.Id);
            DateTime firstDayOfMonth = new DateTime(SelectedYear.Id, SelectedMonth.Id, 1);
            DateTime lastDayOfMonth  = new DateTime(SelectedYear.Id, SelectedMonth.Id, daysInMonth);

            if (today.Date < lastDayOfMonth.Date)
            {
                await Shell.Current.DisplayAlert("Error", "Timesheet can not be approved prior to the last day of the selected month.", "OK");

                return;
            }

            var request = new Model.Requests.TimeSheetSearchRequest
            {
                Month = SelectedMonth.Id,
                Year  = SelectedYear.Id
            };

            var timesheets = await _serviceTimeSheets.Get <List <Model.DTO.TimeSheetDTO> >(request);

            if (timesheets.Where(x => x.Status == Status.WorkInProgress).Count() == 0)
            {
                await Shell.Current.DisplayAlert("Error", "There are no timesheet entries to approve for the current month.", "OK");

                return;
            }

            List <DateTime> incompleteDates = new List <DateTime>();

            foreach (var item in timesheets)
            {
                if (item.DayType != DayType.Vacation && item.DayType != DayType.Sick)
                {
                    if (item.StartTime is null || item.EndTime is null || item.BreakTime is null || item.MetersSquared is null || item.KmStand is null)
                    {
                        incompleteDates.Add(item.EntryDate);
                    }
                }
            }

            if (incompleteDates.Count > 0)
            {
                string allDates = "";
                foreach (var date in incompleteDates)
                {
                    if (allDates != "")
                    {
                        allDates += ", ";
                    }

                    allDates += date.ToShortDateString();
                }
                await Shell.Current.DisplayAlert("Error", "Timesheet is incomplete for the following dates: " + allDates, "OK");

                return;
            }

            var asyncTaskList = new List <Task>();

            foreach (var item in timesheets)
            {
                item.Status = Status.ApprovedByEmployee;

                var asyncUpdateTask = _serviceTimeSheets.Update <Model.DTO.TimeSheetDTO>(item.TimeSheetId, item);

                asyncTaskList.Add(asyncUpdateTask);
            }

            await Task.WhenAll(asyncTaskList);

            var requestInsert = new Model.Requests.RequestInsertRequest
            {
                StartDateTime = firstDayOfMonth,
                EndDateTime   = lastDayOfMonth,
                RequestType   = RequestType.TimeSheet,
                Status        = RequestStatus.Pending
            };
            var createdRequest = await _serviceRequests.Insert <Model.DTO.RequestDTO>(requestInsert);

            if (createdRequest != null)
            {
                await Shell.Current.DisplayAlert("Success", "Timesheet for the past month has been approved.", "OK");
            }
        }