// 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")); }
// 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 (UploadFile != null) { if (UploadFile.Length > 0) { var fileName = Guid.NewGuid().ToString() + Path.GetExtension(UploadFile.FileName); var dir = Path.Combine(hostingEnvironment.ContentRootPath, "wwwroot/imageUpload"); Notice.NoticeImagePath = fileName; var filePath = Path.Combine(dir, fileName); using (var stream = System.IO.File.Create(filePath)) { await UploadFile.CopyToAsync(stream); } } } else { return(Page()); } //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.Notices.Add(Notice); await _context.SaveChangesAsync(); 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(); await _hubContext.Clients.All.SendAsync("Reload"); return(RedirectToPage("./Index")); }
public async Task <IActionResult> OnPostAsync(int?id) { if (id == null) { return(NotFound()); } Notice = await _context.Notices.FindAsync(id); if (Notice != null) { _context.Notices.Remove(Notice); await _context.SaveChangesAsync(); } //Delete the local file var dir = Path.Combine(hostingEnvironment.ContentRootPath, "wwwroot/imageUpload"); var filePath = Path.Combine(dir, Notice.NoticeImagePath); if (System.IO.File.Exists(filePath)) { System.IO.File.Delete(filePath); } 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() { 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() { if (!ModelState.IsValid) { return(Page()); } _context.NoticeDisplays.Add(NoticeDisplay); await _context.SaveChangesAsync(); await _hubContext.Clients.All.SendAsync("Reload"); return(RedirectToPage("./Index")); }
public async Task <IActionResult> OnPostAsync(int?id) { if (id == null) { return(NotFound()); } NoticeDisplay = await _context.NoticeDisplays.FindAsync(id); if (NoticeDisplay != null) { _context.NoticeDisplays.Remove(NoticeDisplay); await _context.SaveChangesAsync(); } await _hubContext.Clients.All.SendAsync("Reload"); return(RedirectToPage("./Index")); }