Beispiel #1
0
        public async Task <IActionResult> Create(PacientViewModel view)
        {
            if (ModelState.IsValid)
            {
                var path = string.Empty;

                if (view.PictureFile != null && view.PictureFile.Length > 0)
                {
                    var guid = Guid.NewGuid().ToString();
                    var file = $"{guid}.jpg";


                    path = Path.Combine(
                        Directory.GetCurrentDirectory(),
                        "wwwroot\\images\\Pacients",
                        file);

                    using (var stream = new FileStream(path, FileMode.Create))
                    {
                        await view.PictureFile.CopyToAsync(stream);
                    }

                    path = $"~/images/Pacients/{file}";
                }

                var pacient = this.ToPacient(view, path);
                pacient.User = await this.userHelper.GetUserByEmailAsync(this.User.Identity.Name);

                await this.pacientRepository.CreateAsync(pacient);

                return(RedirectToAction(nameof(Index)));
            }

            return(View(view));
        }
        public PacientDetailsViewModel(PacientViewModel pacientViewModel)
        {
            Pacient = new PacientViewModel();
            if (pacientViewModel.Id != 0)
            {
                Pacient.Id                   = pacientViewModel.Id;
                Pacient.GrupaDeSange         = pacientViewModel.GrupaDeSange;
                Pacient.DataNastere          = pacientViewModel.DataNastere;
                Pacient.IdGrupaDeSange       = pacientViewModel.IdGrupaDeSange;
                Pacient.InstitutieAsociata   = pacientViewModel.InstitutieAsociata;
                Pacient.IdInstitutieAsociata = pacientViewModel.IdInstitutieAsociata;
                Pacient.Nume                 = pacientViewModel.Nume;
                Pacient.Prenume              = pacientViewModel.Prenume;
            }
            GrupeDeSange       = new ObservableCollection <GrupaDeSange>(AppService.Instance.GrupaDeSangeService.GetAll());
            InstitutiiAsociate = new ObservableCollection <InstitutieAsociata>(AppService.Instance.InstitutieAsociataService.GetAll());
            if (pacientViewModel.Id == 0)
            {
                SelectedGrupa      = GrupeDeSange[0];
                SelectedInstitutie = InstitutiiAsociate[0];
            }
            else
            {
                SelectedInstitutie = Pacient.InstitutieAsociata;
                SelectedGrupa      = Pacient.GrupaDeSange;
            }

            SalveazaCommand = new BasicCommand(Salveaza);
        }
Beispiel #3
0
        public async Task <IActionResult> EditPostAsync(PacientViewModel dto)
        {
            if (ModelState.IsValid)
            {
                await Service.SaveAsync(dto);
            }

            return(RedirectToAction(nameof(Index)));
        }
Beispiel #4
0
 private Pacients ToPacient(PacientViewModel view, string path)
 {
     return(new Pacients
     {
         Id = view.Id,
         Name = view.Name,
         Address = view.Address,
         BirthDate = view.BirthDate,
         PictureUrl = path,
         User = view.User
     });
 }
        private void Salveaza()
        {
            if (string.IsNullOrWhiteSpace(Pacient.Nume) ||
                string.IsNullOrWhiteSpace(Pacient.Prenume))
            {
                MessageBox.Show("Date invalide.", "Warning", MessageBoxButton.OK, MessageBoxImage.Information);
            }
            else
            {
                try
                {
                    var pacient = new Pacient();
                    pacient.Nume               = Pacient.Nume;
                    pacient.Prenume            = Pacient.Prenume;
                    pacient.GrupaDeSange       = SelectedGrupa.Id;
                    pacient.InstitutieAsociata = SelectedInstitutie.Id;
                    pacient.DataNastere        = Pacient.DataNastere;


                    var pacientVm = new PacientViewModel(pacient);
                    pacientVm.GrupaDeSange       = SelectedGrupa;
                    pacientVm.InstitutieAsociata = SelectedInstitutie;

                    if (Pacient.Id == 0)
                    {
                        // add
                        AppService.Instance.PacientService.Add(pacient);
                        pacientVm.Id = pacient.Id;
                        PacientAdded?.Invoke(this, pacientVm);
                    }
                    else
                    {
                        // update
                        pacient.Id   = Pacient.Id;
                        pacientVm.Id = Pacient.Id;
                        AppService.Instance.PacientService.Update(pacient);
                        PacientUpdated?.Invoke(this, pacientVm);
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "Warning", MessageBoxButton.OK, MessageBoxImage.Information);
                }
            }
        }
 public PacientsPage()
 {
     InitializeComponent();
     DataContext = new PacientViewModel(IoC.Container.Resolve <DataContext>());
 }