public IActionResult OnGet(int id) { var currentUser = this.userManager.GetUserAsync(this.User).Result; this.CourseInstance = this.contex.CourseInstances.FirstOrDefault(ci => ci.Id == id); // bool hasSuchUser = this.CourseInstance.Students.Any(ci => ci.StudentId == currentUser.Id); if (this.CourseInstance == null) { return(RedirectToPage("NoInsyances")); } bool hasSuchUser = this.contex.StudentsInCourses.Any(c => c.CourseId == CourseInstance.Id && c.StudentId == currentUser.Id); if (hasSuchUser) { return(RedirectToPage("AlreadyEnrolled")); } var studentInCourse = new StudentsInCourses() { StudentId = currentUser.Id, CourseId = this.CourseInstance.Id }; this.contex.StudentsInCourses.Add(studentInCourse); this.CourseInstance.Students.Add(studentInCourse); this.contex.SaveChanges(); return(Page()); }
public async Task ProcessPaymentAsync(PaymentBindingModel model, IEnumerable <Models.Payment> payments) { var payment = new Payment { id = model.PaymentId, token = model.Token }; var executed = payment .Execute(this.apiContext, new PaymentExecution { payer_id = model.PayerId }); foreach (var payment1 in payments) { payment1.PayPalPaymentId = model.PaymentId; payment1.Username = model.Username; payment1.StudentId = model.StudentId; } await this.repository.AddRangeAsync(payments); StudentsInCourses studentsInCourses = null; foreach (var payment2 in payments) { studentsInCourses = new StudentsInCourses { CourseId = payment2.CourseId, StudentId = payment2.StudentId }; } await this.studentsInCourseRepository.AddAsync(studentsInCourses); }