public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } /* Changed to allow location creation with only knowing the country of origin. */ var newLocation = new Location { LocationCode = LocationCreateVM.LocationCode, DivisionID = LocationCreateVM.DivisionID, BusinessUnitID = LocationCreateVM.BusinessUnitID, Address = new Address { StateProvince = LocationCreateVM.StateProvince, Country = LocationCreateVM.Country } }; _context.Location.Add(newLocation); await _context.SaveChangesAsync(); return(RedirectToPage("./Index")); //_context.Add(new Location()); //newLocation.Context.Add(new Address()); //newLocation.CurrentValues.SetValues(LocationCreateVM); //await newLocation.Context.SaveChangesAsync(); }
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) { await PopulateDropDownLists(_context); return(Page()); } var assessmentToCreate = new Assessment() { LocationID = AssessmentCreateVM.LocationID, VendorID = AssessmentCreateVM.VendorID, StatusID = AssessmentCreateVM.StatusID, StudyRequired = AssessmentCreateVM.StudyRequired, StartDate = AssessmentCreateVM.StartDate, EndDate = AssessmentCreateVM.EndDate, Comment = AssessmentCreateVM.Comment }; if (await TryUpdateModelAsync <Assessment>(assessmentToCreate)) { _context.Assessment.Add(assessmentToCreate); await _context.SaveChangesAsync(); return(RedirectToPage("../Details/", new { id = AssessmentCreateVM.LocationID })); } await PopulateDropDownLists(_context); return(Page()); }
public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } var studyHistoryToCreate = new StudyHistory() { StudyID = StudyHistoryCreateVM.StudyID, StatusID = StudyHistoryCreateVM.StatusID, StudyTypeID = StudyHistoryCreateVM.StudyTypeID, VendorID = StudyHistoryCreateVM.VendorID, UnderratedIssues = StudyHistoryCreateVM.UnderratedIssues, ArcFlashIssues = StudyHistoryCreateVM.ArcFlashIssues, EquipmentProtectionIssues = StudyHistoryCreateVM.EquipmentProtectionIssues, StartDate = StudyHistoryCreateVM.StartDate, EndDate = StudyHistoryCreateVM.EndDate, ExpirationDate = CheckExpirationDate(StudyHistoryCreateVM.EndDate), Comment = StudyHistoryCreateVM.Comment }; _context.StudyHistory.Add(studyHistoryToCreate); await _context.SaveChangesAsync(); return(RedirectToPage("../Details/", new { id = StudyHistoryCreateVM.StudyID })); }
public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } var studyToCreate = new Study { StudyName = StudyCreateVM.StudyName, StudySize = StudyCreateVM.StudySize, }; if (StudyCreateVM.SelectedLocations != null) { studyToCreate.LocationStudies = new List <LocationStudy>(); foreach (int selectedLocation in StudyCreateVM.SelectedLocations) { studyToCreate.LocationStudies.Add(new LocationStudy() { StudyID = studyToCreate.StudyID, LocationID = selectedLocation }); } } _context.Study.Add(studyToCreate); await _context.SaveChangesAsync(); 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 })); }
public async Task <IActionResult> OnPostAsync(int?id) { if (id == null) { return(NotFound()); } Study = await _context.Study.FindAsync(id); if (Study != null) { _context.Study.Remove(Study); await _context.SaveChangesAsync(); } return(RedirectToPage("./Index")); }
public async Task <IActionResult> OnPostAsync(int?id) { if (id == null) { return(NotFound()); } var vendorToDelete = await _context.Vendor.FindAsync(id); if (vendorToDelete != null) { _context.Vendor.Remove(vendorToDelete); await _context.SaveChangesAsync(); } return(RedirectToPage("./Index")); }
public static void Initialize(TrackerContext context) { context.Database.Migrate(); InitializeLocations(context); InitializeDivisions(context); InitializeAddresses(context); InitializeStudies(context); InitializeStatuses(context); InitializeStudyTypes(context); InitializeBusinessUnits(context); InitializeAssessments(context); InitializeCountries(context); InitializeSubdivisions(context); InitializeVendors(context); context.SaveChangesAsync(); }
public async Task <IActionResult> OnPostAsync(int?id) { if (id == null) { return(NotFound()); } var assessmentToDelete = await _context.Assessment.FirstOrDefaultAsync(a => a.AssessmentID == id); if (assessmentToDelete != null) { _context.Assessment.Remove(assessmentToDelete); await _context.SaveChangesAsync(); } return(RedirectToPage("./Index")); }
public async Task <IActionResult> OnPostAsync(int?id) { if (id == null) { return(NotFound()); } LocationDeleteVM = await _context.Location.Select(l => new LocationDeleteViewModel() { LocationID = l.LocationID, LocationCode = l.LocationCode, DivisionName = l.Division.DivisionName, AddressID = l.AddressID, StateProvince = l.Address.StateProvince, Country = l.Address.Country }).FirstOrDefaultAsync(l => l.LocationID == id); var locationToDelete = new Location { LocationID = LocationDeleteVM.LocationID, LocationCode = LocationDeleteVM.LocationCode, AddressID = LocationDeleteVM.AddressID, Address = new Address { AddressID = LocationDeleteVM.AddressID, StateProvince = LocationDeleteVM.StateProvince, Country = LocationDeleteVM.Country } /* * Address = new Address * { * StateProvince = LocationDeleteVM.StateProvince, * Country = LocationDeleteVM.Country * }*/ }; if (locationToDelete != null) { _context.Location.Remove(locationToDelete); await _context.SaveChangesAsync(); } return(RedirectToPage("./Index")); }
public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } var vendorToCreate = new Vendor { VendorNumber = VendorVM.VendorNumber, VendorName = VendorVM.VendorName }; _context.Vendor.Add(vendorToCreate); await _context.SaveChangesAsync(); return(RedirectToPage("./Index")); }
public async Task <IActionResult> OnPostAsync(int id) { if (!ModelState.IsValid) { return(Page()); } var resultToCreate = new StudyResult { StudyID = id, UnderratedIssues = StudyResultVM.UnderratedIssues, ArcFlashIssues = StudyResultVM.ArcFlashIssues, EquipmentProtectionIssues = StudyResultVM.EquipmentProtectionIssues, DateCompleted = StudyResultVM.DateCompleted }; _context.StudyResult.Add(resultToCreate); await _context.SaveChangesAsync(); return(RedirectToPage("../Details/", new { id })); }
public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { await PopulateDropDownLists(_context); return(Page()); } var assessmentToEdit = new Assessment { AssessmentID = AssessmentVM.AssessmentID, LocationID = AssessmentVM.LocationID, StatusID = AssessmentVM.StatusID, VendorID = AssessmentVM.VendorID, StudyRequired = AssessmentVM.StudyRequired, StartDate = AssessmentVM.StartDate, EndDate = AssessmentVM.EndDate, Comment = AssessmentVM.Comment, }; try { _context.Update(assessmentToEdit); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!AssessmentExists(assessmentToEdit.AssessmentID)) { return(NotFound()); } else { throw; } } return(RedirectToPage("./Index")); }
public async Task <IActionResult> OnPostAsync(int?id) { if (id == null) { return(NotFound()); } var studyHistoryToDelete = new StudyHistory { StudyHistoryID = StudyHistoryDeleteVM.StudyHistoryID, StudyTypeID = StudyHistoryDeleteVM.StudyTypeID, StudyID = StudyHistoryDeleteVM.StudyHistoryID }; if (studyHistoryToDelete != null) { _context.StudyHistory.Remove(studyHistoryToDelete); await _context.SaveChangesAsync(); } return(RedirectToPage("../Details/", new { id = StudyHistoryDeleteVM.StudyID })); }
public async Task <IActionResult> OnPostAsync(int?id) { if (!ModelState.IsValid) { return(Page()); } var locationToEdit = await _context.Location.AsTracking().Include(l => l.Address).FirstOrDefaultAsync(l => l.LocationID == id); if (locationToEdit != null) { locationToEdit.LocationCode = LocationEditVM.LocationCode; locationToEdit.DivisionID = LocationEditVM.DivisionID; locationToEdit.BusinessUnitID = LocationEditVM.BusinessUnitID; locationToEdit.Address.FirstAddress = LocationEditVM.FirstAddress; locationToEdit.Address.SecondAddress = LocationEditVM.SecondAddress; locationToEdit.Address.City = LocationEditVM.City; locationToEdit.Address.StateProvince = LocationEditVM.StateProvince; locationToEdit.Address.Country = LocationEditVM.Country; locationToEdit.Address.Lattitude = LocationEditVM.Lattitude; locationToEdit.Address.Longitude = LocationEditVM.Longitude; } else { return(NotFound()); } if (await TryUpdateModelAsync <Location>(locationToEdit, "location", l => l.LocationCode, l => l.AddressID, l => l.DivisionID)) { await _context.SaveChangesAsync(); return(RedirectToPage("./Index")); } return(Page()); }