private async Task ExecuteSubmitRequestCommand() { if (SelectedRequestType == null) { await Shell.Current.DisplayAlert("Error", "Request type is a required field.", "OK"); return; } var StartDateTime = StartDate.Date; var EndDateTime = EndDate.Date; if (TimeEditable) { StartDateTime = StartDateTime.Add(StartTime); EndDateTime = EndDateTime.Add(EndTime); if (StartTime > EndTime) { await Shell.Current.DisplayAlert("Error", "Start time has to be before End time.", "OK"); return; } } if (StartDateTime > EndDateTime) { await Shell.Current.DisplayAlert("Error", "Start date has to be before End date.", "OK"); return; } var request = new Model.Requests.RequestInsertRequest { StartDateTime = StartDateTime, EndDateTime = EndDateTime, RequestType = (RequestType)SelectedRequestType.Id, Status = RequestStatus.Pending, }; var result = await _serviceRequests.Insert <Model.DTO.RequestDTO>(request); if (result != null) { await Shell.Current.Navigation.PopAsync(); } }
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"); } }