// To protect from overposting attacks, enable the specific properties you want to bind to, for // more details, see https://aka.ms/RazorPagesCRUD. public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } _context.Attach(NoticeDisplay).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!NoticeDisplayExists(NoticeDisplay.NoticeDisplayID)) { return(NotFound()); } else { throw; } } await _hubContext.Clients.All.SendAsync("Reload"); return(RedirectToPage("./Index")); }
// To protect from overposting attacks, enable the specific properties you want to bind to, for // more details, see https://aka.ms/RazorPagesCRUD. public async Task <IActionResult> OnPostAsync() { //Set the date enable bit so that the model is still valid Notice.NoticeStartDate = DateTime.Now; Notice.NoticeStopDate = DateTime.Now; Notice.EnabelStopDate = false; if (!ModelState.IsValid) { return(Page()); } _context.Attach(Notice).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!NoticeExists(Notice.NoticeID)) { return(NotFound()); } else { throw; } } //This could probably be done better but this should work for now. //Delete the old assignments List <NoticeAssignment> assignments = await _context.NoticeAssignments.Where(m => m.NoticeID == Notice.NoticeID).ToListAsync(); foreach (var assignment in assignments) { _context.NoticeAssignments.Remove(assignment); } await _context.SaveChangesAsync(); //Add the new assignmnets NoticeAssignments = new List <NoticeAssignment>(); foreach (var display in checkedDisplays) { NoticeAssignment assignment = new NoticeAssignment(); assignment.NoticeID = Notice.NoticeID; assignment.NoticeDisplayID = display; NoticeAssignments.Add(assignment); } _context.NoticeAssignments.AddRange(NoticeAssignments); await _context.SaveChangesAsync(); //Reload the client displays await _hubContext.Clients.All.SendAsync("Reload"); return(RedirectToPage("./Index")); }