/// <summary> /// Adds the prescription to the AllPrescriptions property or refreshes it if it's a new group. /// </summary> /// <param name="item"></param> public async void AddPrescriptionToCollection(Prescription item) { bool isSessionPresent = AllPrescriptions.Any(p => p.TimeStamp == item.Schedule); if (isSessionPresent) { AllPrescriptions.Single(grp => grp.TimeStamp == item.Schedule).Prescriptions.Add(item); } else { await RefreshDataAsync(); } }
/// <summary> /// Removes the prescription. /// </summary> /// <param name="selectedItem"></param> public async void DeletePrescription(object selectedItem) { try { Prescription item = selectedItem as Prescription; await imsSvc.DeletePrescriptionAsync(item); var group = AllPrescriptions.Single(grp => grp.TimeStamp == item.Schedule); if (group.Prescriptions.Count > 1) { AllPrescriptions.Single(grp => grp.TimeStamp == item.Schedule).Prescriptions.Remove(item); Prescriptions.Single(grp => grp.TimeStamp == item.Schedule).Prescriptions.Remove(item); } else { AllPrescriptions.Remove(group); Prescriptions.Remove(group); } } catch (Exception e) { MessengerInstance.Send(new ExceptionDialogMessage(e)); } }