Exemplo n.º 1
0
 public CerereDetailViewModel(CerereViewModel ViewModel)
 {
     if (ViewModel.Id == 0)
     {
         FieldsEnabled    = true;
         DetailButtonText = "Add";
         SelectedGrupa    = GrupeDeSange.First();
         SelectedTip      = TipuriComponenta.First();
         SelectedStare    = StariPosibile.First();
     }
     else
     {
         FieldsEnabled    = false;
         DetailButtonText = "Update";
         NumePacient      = ViewModel.Pacient.Nume;
         PrenumePacient   = ViewModel.Pacient.Prenume;
         SelectedTip      = ViewModel.TipComponenta;
         SelectedGrupa    = ViewModel.GrupaDeSange;
         SelectedStare    = ViewModel.Stare;
     }
     CerereViewModel = ViewModel;
     AddCommand      = new BasicCommand(Save);
     CancelCommand   = new BasicCommandWithParameter(Cancel);
 }
Exemplo n.º 2
0
        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);
                }
            }
        }