Esempio n. 1
0
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }
            List <CourseInfo> CourseInfos = HttpContext.Session.Get <List <CourseInfo> >("CourseInfo");

            user = HttpContext.Session.Get <ApplicationUser>("UserInfo");

            Enrollment = await _context.Enrollment
                         .Include(e => e.ApplicationUser)
                         .Include(e => e.Section).FirstOrDefaultAsync(m => m.Id == id);

            CourseInfos.RemoveAll(c => c.SectionId == Enrollment.SectionId);
            HttpContext.Session.Set <List <CourseInfo> >("CourseInfo", CourseInfos);


            Course = _context.Course.FirstOrDefault(c => c.Id == Enrollment.Section.CourseId);
            Charge Charge = new Charge();

            Charge.Reason    = "Withdraw from " + Course.Subject + " " + Course.Number + " Section " + Enrollment.SectionId;
            Charge.Date      = DateTime.Now;
            Charge.Amount    = -1 * (Course.CreditHours * SD.CostPerCredit + Course.CourseFee);
            Charge.StudentId = user.Id;
            if (Enrollment != null)
            {
                DataAccessClass dataAccess = new DataAccessClass();
                dataAccess.RemoveEnrollment(Enrollment);
                dataAccess.AddCharge(Charge);
            }

            return(RedirectToPage("./Index"));
        }