public void FilterCereri() { int? ParamGrupa; string ParamStare; string ParamTip; if (SelectedStare.CompareTo(Stari[0]) == 0) { ParamStare = null; } else { ParamStare = SelectedStare; } if (SelectedTip.CompareTo(Tipuri[0]) == 0) { ParamTip = null; } else { ParamTip = SelectedTip; } if (SelectedGrupa == Grupe[0]) { ParamGrupa = null; } else { ParamGrupa = SelectedGrupa.Id; } var cereri = AppService.Instance.CerereService.Filter(ParamGrupa, ParamTip, ParamStare); Cereri.Clear(); foreach (var c in cereri) { Cereri.Add(new CerereViewModel(c)); } }
public void Save() { if (String.IsNullOrEmpty(NumePacient) || String.IsNullOrEmpty(PrenumePacient) || SelectedGrupa == null) { MessageBox.Show("Please make sure you completed all the fields!", "Error", MessageBoxButton.OK); } else { try { Pacient Pacient = AppService.Instance.PacientService.GetPacientByFullName(NumePacient, PrenumePacient).First(); CerereViewModel.IdMedic = AppSettings.LoggedMedic.Id; CerereViewModel.IdPacient = Pacient.Id; CerereViewModel.IdGrupaDeSange = SelectedGrupa.Id; CerereViewModel.Medic = AppSettings.LoggedMedic; CerereViewModel.Pacient = Pacient; CerereViewModel.TipComponenta = SelectedTip; CerereViewModel.GrupaDeSange = SelectedGrupa; CerereViewModel.Stare = SelectedStare; CerereViewModel.DataDepunere = DateTime.Now; if (SelectedStare.CompareTo(StariPosibile.First()) != 0) { CerereViewModel.DataServire = DateTime.Now; } else { CerereViewModel.DataServire = DateTime.Parse("1970-01-01 00:00:00"); } var Cerere = new CerereMedicPacient() { Id = CerereViewModel.Id, IdPacient = CerereViewModel.IdPacient, IdMedic = CerereViewModel.IdMedic, GrupaDeSange = CerereViewModel.IdGrupaDeSange, TipComponenta = CerereViewModel.TipComponenta, Stare = CerereViewModel.Stare, DataDepunere = CerereViewModel.DataDepunere, DataServire = CerereViewModel.DataServire, GrupaDeSange1 = CerereViewModel.GrupaDeSange, Medic = CerereViewModel.Medic, Pacient = CerereViewModel.Pacient }; if (CerereViewModel.Id == 0) { AppService.Instance.CerereService.Add(Cerere); CerereAdded?.Invoke(this, Cerere); MessageBox.Show("Cerere added successfully!", "Success", MessageBoxButton.OK); } else { AppService.Instance.CerereService.Update(Cerere); CerereUpdated?.Invoke(this, Cerere); MessageBox.Show("Cerere updated successfully!", "Success", MessageBoxButton.OK); } } catch (ServiceException e) { MessageBox.Show(e.Message, "Error", MessageBoxButton.OK); } catch (InvalidOperationException) { MessageBox.Show("Pacient not found or there is a problem with the database", "Error", MessageBoxButton.OK); } } }