public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            _context.Attach(StudyResult).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!StudyResultExists(StudyResult.StudyResultID))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(RedirectToPage("./Index"));
        }
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            var studyToEdit = _context.Study.Include(s => s.LocationStudies).FirstOrDefault(s => s.StudyID == StudyEditVM.StudyID);

            //studyToEdit.LocationStudies = await _context.LocationStudy.Where(ls => ls.StudyID == StudyEditVM.StudyID).ToListAsync();

            _context.Attach(studyToEdit).State = EntityState.Modified;

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

            studyToEdit.StudyID   = StudyEditVM.StudyID;
            studyToEdit.StudyName = StudyEditVM.StudyName;
            studyToEdit.StudySize = StudyEditVM.StudySize;

            //Remove LocationStudy if it has not been selected
            studyToEdit.LocationStudies.Where(ls => !StudyEditVM.SelectedLocations.Contains(ls.LocationID))
            .ToList().ForEach(remls => studyToEdit.LocationStudies.Remove(remls));

            //Add LocationStudy if it remains in the list after excluding prior location studies

            var existingLocationStudies    = studyToEdit.LocationStudies.Select(ls => ls.LocationID);
            var nonExistingLocationStudies = StudyEditVM.SelectedLocations.Except(existingLocationStudies).ToList();

            foreach (int locationStudy in nonExistingLocationStudies)
            {
                studyToEdit.LocationStudies.Add(new LocationStudy
                {
                    StudyID    = StudyEditVM.StudyID,
                    LocationID = locationStudy
                });
            }

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!StudyExists(studyToEdit.StudyID))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(RedirectToPage("./Index"));
        }
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }



            var studyHistoryToEdit = await _context.StudyHistory.FirstOrDefaultAsync(sh => sh.StudyHistoryID == StudyHistoryEditVM.StudyHistoryID);

            studyHistoryToEdit.StudyHistoryID            = StudyHistoryEditVM.StudyHistoryID;
            studyHistoryToEdit.StudyID                   = StudyHistoryEditVM.StudyID;
            studyHistoryToEdit.StatusID                  = StudyHistoryEditVM.StatusID;
            studyHistoryToEdit.VendorID                  = StudyHistoryEditVM.VendorID;
            studyHistoryToEdit.StartDate                 = StudyHistoryEditVM.StartDate;
            studyHistoryToEdit.EndDate                   = StudyHistoryEditVM.EndDate;
            studyHistoryToEdit.ExpirationDate            = CheckExpirationDate(StudyHistoryEditVM.EndDate);
            studyHistoryToEdit.UnderratedIssues          = StudyHistoryEditVM.UnderratedIssues;
            studyHistoryToEdit.ArcFlashIssues            = StudyHistoryEditVM.ArcFlashIssues;
            studyHistoryToEdit.EquipmentProtectionIssues = StudyHistoryEditVM.EquipmentProtectionIssues;

            _context.Attach(studyHistoryToEdit).State = EntityState.Modified;
            if (await TryUpdateModelAsync <StudyHistory>(studyHistoryToEdit, "StudyHistory",
                                                         sh => sh.StatusID,
                                                         sh => sh.VendorID,
                                                         sh => sh.StudyTypeID,
                                                         sh => sh.StartDate,
                                                         sh => sh.EndDate,
                                                         sh => sh.ExpirationDate,
                                                         sh => sh.UnderratedIssues,
                                                         sh => sh.ArcFlashIssues,
                                                         sh => sh.EquipmentProtectionIssues))
            {
                try
                {
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!StudyHistoryExists(studyHistoryToEdit.StudyHistoryID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
            }


            return(RedirectToPage("../Details/", new { id = StudyHistoryEditVM.StudyID }));
        }