public async Task <IActionResult> Edit(int?id, MedicalTrial medicalTrial)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var dbMedicalTrial = await _context.MedicalTrials
                                 .AsNoTracking()
                                 .SingleOrDefaultAsync(m => m.ID == id);

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

            ViewBag.InvestigatorsIds = _listResolver
                                       .PopulatePrimaryInvestigatorDropdownList(dbMedicalTrial.MedicalTrialPrincipalInvestigatorId);
            ViewBag.MedicalTrialsTypeIds = _listResolver
                                           .PopulateMedicalTrialTypesDropdownList(dbMedicalTrial.MedicalTrialTypeId);
            ViewBag.MedicalTrialsStatusesIds = _listResolver
                                               .PopulateMedicalTrialStatusesDropdownList(dbMedicalTrial.MedicalTrialStatusId);

            return(PartialView(@"/Views/MedicalTrials/MedicalTrials/Edit.cshtml", dbMedicalTrial));
        }
        public async Task <IActionResult> EditMedicalTrial(int?id, MedicalTrial medicalTrial)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var dbMedicalTrial = await _context.MedicalTrials
                                 .AsNoTracking()
                                 .SingleOrDefaultAsync(m => m.ID == id);

            UpdateMedicalTrial(dbMedicalTrial, medicalTrial);
            if (TryValidateModel(dbMedicalTrial))
            {
                try
                {
                    _context.MedicalTrials.Update(dbMedicalTrial);
                    _context.SaveChanges();
                }
                catch (DbUpdateException /* ex */)
                {
                    ModelState.AddModelError("", "Unable to save changes. " +
                                             "Try again, and if the problem persists, " +
                                             "see your system administrator.");
                }
            }
            else
            {
                Hashtable errors = ModelStateHelper.Errors(ModelState);
                return(Json(new { success = false, errors }));
            }

            return(Json(new { result = "ok" }));
        }
        public async Task <IActionResult> Edit(int id, [Bind("ID,TrialName")] MedicalTrial medicalTrial)
        {
            if (id != medicalTrial.ID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(medicalTrial);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!MedicalTrialExists(medicalTrial.ID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(medicalTrial));
        }
        public async Task <IActionResult> Create([Bind("ID,TrialName")] MedicalTrial medicalTrial)
        {
            if (ModelState.IsValid)
            {
                _context.Add(medicalTrial);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(medicalTrial));
        }
 private void UpdateMedicalTrial(MedicalTrial dbMedicalTrial,
                                 MedicalTrial medicalTrial)
 {
     dbMedicalTrial.Description = medicalTrial.Description;
     dbMedicalTrial.MedicalTrialPrincipalInvestigatorId = medicalTrial.MedicalTrialPrincipalInvestigatorId;
     dbMedicalTrial.MedicalTrialStatusId = medicalTrial.MedicalTrialStatusId;
     dbMedicalTrial.MedicalTrialTypeId   = medicalTrial.MedicalTrialTypeId;
     dbMedicalTrial.Name        = medicalTrial.Name;
     dbMedicalTrial.Number      = medicalTrial.Number;
     dbMedicalTrial.RandDNumber = medicalTrial.RandDNumber;
     dbMedicalTrial.RECNumber   = medicalTrial.RECNumber;
 }
        public async Task <IActionResult> Create(MedicalTrial medicalTrial)
        {
            try
            {
                this.CheckFieldUniqueness(_context.MedicalTrials, "Name", medicalTrial.Name);

                if (ModelState.IsValid)
                {
                    _context.Add(medicalTrial);
                    await _context.SaveChangesAsync();

                    return(Json(new { result = "ok" }));
                }
                else
                {
                    Hashtable errors = ModelStateHelper.Errors(ModelState);
                    return(Json(new { success = false, errors }));
                }
            }
            catch (DbUpdateException)
            {
                return(null);
            }
        }
Esempio n. 7
0
        public async Task <IActionResult> Edit(int id, string[] selectedOptions,
                                               string chkRemoveImage, Byte[] RowVersion, IFormFile thePicture)
        {
            //Get the URL with the last filter, sort and page parameters
            ViewData["returnURL"] = MaintainURL.ReturnURL(HttpContext, "Patients");

            //Go get the patient to update
            var patientToUpdate = await _context.Patients
                                  .Include(p => p.Doctor)
                                  .Include(p => p.MedicalTrial)
                                  .Include(p => p.PatientPhoto).ThenInclude(p => p.PhotoContentFull)
                                  .Include(p => p.PatientConditions).ThenInclude(p => p.Condition)
                                  .SingleOrDefaultAsync(p => p.ID == id);

            //Check that you got it or exit with a not found error
            if (patientToUpdate == null)
            {
                return(NotFound());
            }

            //Update the medical history
            UpdatePatientConditions(selectedOptions, patientToUpdate);

            //Put the original RowVersion value in the OriginalValues collection for the entity
            _context.Entry(patientToUpdate).Property("RowVersion").OriginalValue = RowVersion;

            //Try updating it with the values posted
            if (await TryUpdateModelAsync <Patient>(patientToUpdate, "",
                                                    p => p.OHIP, p => p.FirstName, p => p.MiddleName, p => p.LastName, p => p.DOB,
                                                    p => p.ExpYrVisits, p => p.Phone, p => p.eMail, p => p.MedicalTrialID, p => p.DoctorID))
            {
                try
                {
                    //For the image
                    if (chkRemoveImage != null)
                    {
                        patientToUpdate.PatientPhoto = null;
                    }
                    else
                    {
                        await AddPicture(patientToUpdate, thePicture);
                    }
                    await _context.SaveChangesAsync();

                    //Send on to add appointments
                    return(RedirectToAction("Index", "PatientAppt", new { PatientID = patientToUpdate.ID }));
                }
                catch (RetryLimitExceededException /* dex */)
                {
                    ModelState.AddModelError("", "Unable to save changes after multiple attempts. Try again, and if the problem persists, see your system administrator.");
                }
                catch (DbUpdateConcurrencyException ex)// Added for concurrency
                {
                    var exceptionEntry = ex.Entries.Single();
                    var clientValues   = (Patient)exceptionEntry.Entity;
                    var databaseEntry  = exceptionEntry.GetDatabaseValues();
                    if (databaseEntry == null)
                    {
                        ModelState.AddModelError("",
                                                 "Unable to save changes. The Patient was deleted by another user.");
                    }
                    else
                    {
                        var databaseValues = (Patient)databaseEntry.ToObject();
                        if (databaseValues.FirstName != clientValues.FirstName)
                        {
                            ModelState.AddModelError("FirstName", "Current value: "
                                                     + databaseValues.FirstName);
                        }
                        if (databaseValues.MiddleName != clientValues.MiddleName)
                        {
                            ModelState.AddModelError("MiddleName", "Current value: "
                                                     + databaseValues.MiddleName);
                        }
                        if (databaseValues.LastName != clientValues.LastName)
                        {
                            ModelState.AddModelError("LastName", "Current value: "
                                                     + databaseValues.LastName);
                        }
                        if (databaseValues.OHIP != clientValues.OHIP)
                        {
                            ModelState.AddModelError("OHIP", "Current value: "
                                                     + databaseValues.OHIP);
                        }
                        if (databaseValues.DOB != clientValues.DOB)
                        {
                            ModelState.AddModelError("DOB", "Current value: "
                                                     + String.Format("{0:d}", databaseValues.DOB));
                        }
                        if (databaseValues.Phone != clientValues.Phone)
                        {
                            ModelState.AddModelError("Phone", "Current value: "
                                                     + String.Format("{0:(###) ###-####}", databaseValues.Phone));
                        }
                        if (databaseValues.eMail != clientValues.eMail)
                        {
                            ModelState.AddModelError("eMail", "Current value: "
                                                     + databaseValues.eMail);
                        }
                        if (databaseValues.ExpYrVisits != clientValues.ExpYrVisits)
                        {
                            ModelState.AddModelError("ExpYrVisits", "Current value: "
                                                     + databaseValues.ExpYrVisits);
                        }
                        //For the foreign key, we need to go to the database to get the information to show
                        if (databaseValues.DoctorID != clientValues.DoctorID)
                        {
                            Doctor databaseDoctor = await _context.Doctors.SingleOrDefaultAsync(i => i.ID == databaseValues.DoctorID);

                            ModelState.AddModelError("DoctorID", $"Current value: {databaseDoctor?.FullName}");
                        }
                        //A little extra work for the nullable foreign key.  No sense going to the database and asking for something
                        //we already know is not there.
                        if (databaseValues.MedicalTrialID != clientValues.MedicalTrialID)
                        {
                            if (databaseValues.MedicalTrialID.HasValue)
                            {
                                MedicalTrial databaseMedicalTrial = await _context.MedicalTrials.SingleOrDefaultAsync(i => i.ID == databaseValues.MedicalTrialID);

                                ModelState.AddModelError("MedicalTrialID", $"Current value: {databaseMedicalTrial?.TrialName}");
                            }
                            else

                            {
                                ModelState.AddModelError("MedicalTrialID", $"Current value: None");
                            }
                        }
                        ModelState.AddModelError(string.Empty, "The record you attempted to edit "
                                                 + "was modified by another user after you received your values. The "
                                                 + "edit operation was canceled and the current values in the database "
                                                 + "have been displayed. If you still want to save your version of this record, click "
                                                 + "the Save button again. Otherwise click the 'Back to List' hyperlink.");
                        patientToUpdate.RowVersion = (byte[])databaseValues.RowVersion;
                        ModelState.Remove("RowVersion");
                    }
                }
                catch (DbUpdateException dex)
                {
                    if (dex.GetBaseException().Message.Contains("UNIQUE constraint failed: Patients.OHIP"))
                    {
                        ModelState.AddModelError("OHIP", "Unable to save changes. Remember, you cannot have duplicate OHIP numbers.");
                    }
                    else
                    {
                        ModelState.AddModelError("", "Unable to save changes. Try again, and if the problem persists see your system administrator.");
                    }
                }
            }

            //Validaiton Error so give the user another chance.
            PopulateAssignedConditionData(patientToUpdate);
            PopulateDropDownLists(patientToUpdate);
            return(View(patientToUpdate));
        }