Exemplo n.º 1
0
        //GET Method EDIT
        public async Task <IActionResult> EditDisease(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var disease = await _context.Diseases.FindAsync(id);

            if (disease == null)
            {
                return(NotFound());
            }

            var editDiseaseViewModel = new EditDiseaseViewModel
            {
                PetTypes    = _context.PetTypes.ToList(),
                Id          = disease.Id,
                Title       = disease.Title,
                Description = disease.Description,
                PetTypeId   = disease.PetTypeId
            };

            return(View(editDiseaseViewModel));
        }
Exemplo n.º 2
0
        private EditDiseaseViewModel MapEditDiseaseViewModel(Disease disease = null)
        {
            EditDiseaseViewModel diseaseViewModel = disease == null ? new EditDiseaseViewModel() : MapDiseaseViewModel <EditDiseaseViewModel>(disease);

            diseaseViewModel.AvailablePersons   = _personsRepository.GetPersons().Select(MapPersonViewModel).ToList();
            diseaseViewModel.AvailableSymptoms  = _symptomsRepository.GetSymptoms().Select(MapSymptomViewModel).ToList();
            diseaseViewModel.AvailableDiagnoses = _diagnosesRepositories.GetDiagnoses().Select(MapDiagnosisViewModel).ToList();

            return(diseaseViewModel);
        }
Exemplo n.º 3
0
        public async Task <IActionResult> EditDisease(int id, [Bind("Title,Description,PetTypeId")] EditDiseaseViewModel editDiseaseViewModel)
        {
            var disease = await _context.Diseases.FirstOrDefaultAsync(d => d.Id == id);

            if (disease == null)
            {
                return(NotFound());
            }

            if (await TryUpdateModelAsync(disease))
            {
                try
                {
                    await _context.SaveChangesAsync();
                }
                catch (Exception)
                {
                    throw;
                }
                return(RedirectToAction("Index"));
            }

            return(View(editDiseaseViewModel));
        }