public void SaveInspection() { if (!CheckInput()) { return; } if (SelectedTask == null) { SelectedTask = new Task(); } SelectedTask.Checklist = SelectedChecklist; SelectedTask.Customer = SelectedCustomer; SelectedTask.DateTimeStart = StartDate; SelectedTask.DatetimeCreated = DateTime.Now; SelectedTask.Inspections = new List <Inspection>(); InspectionsDates.ToList().ForEach(i => SelectedTask.Inspections.Add(NewInspectionObject(i))); SelectedTask.ParkingLot = SelectedParkingLot; SelectedTask.Remarks = SelectedTask.Remarks.Trim(); SelectedTask.TaskSchedules = TaskSchedules.ToList(); SelectedTask.DateTimeEnd = IsRepeating ? EndDate : SelectedTask.Inspections.Max(x => x.DateTimePlanned); if (_taskRepository.Add(SelectedTask)) { MessageBox.Show($"Inspectieopdracht voor klant {SelectedCustomer.Name} met {SelectedTask.Inspections.Count} inspecties is opgeslagen"); _router.GoTo(ControlType.TaskOverviewControl); return; } SaveErrorMessage = "Opslaan van inspectieopdracht mislukt."; }
public override void OnEnter() { if (Settings.IsOfflineMode) { MessageBox.Show("Dit scherm is niet beschikbaar in offline mode."); _router.GoBack(); return; } if (_isEditing) { _isEditing = false; return; } if (ViewBag?.Task != null) { SelectedTask = ViewBag.Task; } else { SelectedTask = new Task { Inspections = new List <Inspection>(), TaskSchedules = new List <TaskSchedule>(), DateTimeStart = DateTime.Today, Hash = MD5.Crypt($"{DateTime.Now.ToLongDateString()}-{SelectedTask?.GetHashCode()}") }; EndDate = DateTime.Today.AddDays(1); IsRepeating = false; CanEditStartDate = true; } if (SelectedTask.Remarks == null) { SelectedTask.Remarks = ""; } SelectedTask.TaskSchedules.ToList().ForEach(t => TaskSchedules.Add(t)); Customers.Clear(); ParkingLots.Clear(); Checklists.Clear(); StartDate = DateTime.Today; EndDate = DateTime.Today.AddDays(1); _customerRepository.All().ForEach(Customers.Add); _checklistRepository.All().ForEach(Checklists.Add); _parkingLotRepository.All().ForEach(ParkingLots.Add); CalculateInspectionDates(); SelectFirstComboBoxItem(); }
private void RemoveTaskSchedule() { if (SelectedTaskSchedule == null) { return; } TaskSchedules.Remove(SelectedTaskSchedule); CalculateInspectionDates(); if (TaskSchedules.Count <= 0) { CanEditStartDate = true; } }
private void AddTaskSchedule() { var taskSchedule = new TaskSchedule { IntervalFrequency = IntervalFrequencies.FirstOrDefault(f => f.Name == IntervalFrequency.Day), InspectionDateTime = StartDate, Interval = 1, Task = SelectedTask }; TaskSchedules.Add(taskSchedule); SelectedTaskSchedule = taskSchedule; CalculateInspectionDates(); CanEditStartDate = false; }
private void ClearTaskSchedule() { TaskSchedules.Clear(); CanEditStartDate = true; }