// To protect from overposting attacks, please 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.Enrollment.Add(Enrollment); //await _context.SaveChangesAsync(); DataAccessLayer.DataAccessClass dbAccess = new DataAccessLayer.DataAccessClass(); dbAccess.AddEnrollment(Enrollment); return(RedirectToPage("./Index")); }
public async Task <IActionResult> OnPostAsync(int?id) { user = HttpContext.Session.Get <ApplicationUser>("UserInfo"); Section = await _context.Section .Include(c => c.Course).FirstOrDefaultAsync(m => m.Id == id); Enrollment = new Enrollment(); Enrollment.SectionId = Section.Id; Enrollment.StudentId = user.Id; Charge = new Charge(); Charge.Reason = "Registration for " + Section.Course.Subject + " " + Section.Course.Number + " Section " + Section.Id; Charge.Date = DateTime.Now; Charge.Amount = Section.Course.CreditHours * SD.CostPerCredit + Section.Course.CourseFee; Charge.StudentId = user.Id; if (!ModelState.IsValid) { return(Page()); } //_context.Enrollment.Add(Enrollment); //await _context.SaveChangesAsync(); DataAccessLayer.DataAccessClass dbAccess = new DataAccessLayer.DataAccessClass(); dbAccess.AddEnrollment(Enrollment); dbAccess.AddCharge(Charge); //add new section to the session List <CourseInfo> CourseInfos = HttpContext.Session.Get <List <CourseInfo> >("CourseInfo"); //Course testCourse = _context.Section.Include(e => e.Course).FirstOrDefault(c => c.Id == Enrollment.SectionId).Course; CourseInfo temp = new CourseInfo() { Course = _context.Section.Include(e => e.Course).FirstOrDefault(c => c.Id == Enrollment.SectionId).Course, SectionId = Enrollment.SectionId, Notifications = new List <Notification>(_context.Notification.Where(n => n.SectionId == Enrollment.SectionId).ToList()), Assignments = new List <Assignment>(_context.Assignment.Where(a => a.SectionId == Enrollment.SectionId).ToList()) }; CourseInfos.Add(temp); HttpContext.Session.Set <List <CourseInfo> >("CourseInfo", CourseInfos); return(RedirectToPage("./Index")); }