public IActionResult CreatePayment(CreatePaymentViewModel model) { if (ModelState.IsValid) { Payment newPayment = new Payment { StudentId = model.StudentId, AmouontPaid = model.AmountPaid, PaymentMethod = model.PaymentMethod, PaymentDate = model.PaymentDate }; var student = _er.GetStudent(newPayment.StudentId); ViewBag.Sum = 1000000; if (student.AdmissionType == AddmissionType.IncomeSharing) { var amounPaying = 1000000; var balance = amounPaying - model.AmountPaid; newPayment.AmouontPaid = balance; } var add = _payment.AddPayment(newPayment); return(RedirectToAction("Details", new { id = newPayment.StudentId })); } return(View()); }
public IActionResult Create(Payment payment) { if (ModelState.IsValid) { _payment.AddPayment(payment); return(RedirectToAction("Index")); } return(View()); }
public IActionResult CreatePayment(CreatePaymentViewModel model) { if (ModelState.IsValid) { Payment newPayment = new Payment { EmployeeId = model.EmployeeId, AmouontPaid = model.AmouontPaid, PaymentMethod = model.PaymentMethod, PaymentDate = model.PaymentDate }; _payment.AddPayment(newPayment); return(RedirectToAction("index", "home")); } return(View()); }
public async Task <Unit> Handle(Command request, CancellationToken cancellationToken) { var paymentStatus = _payment.AddPayment(GetPaymentRequest(request)).Result; var success = false; if (paymentStatus.Equals("approved")) { var sqlParams = new object[] { Guid.NewGuid(), request.Amount, DateTime.Now, PaymentStatus.Confirmed, request.OrderId }; success = await _context.Database.ExecuteSqlRawAsync("RegisterPayment @p0, @p1, @p2, @p3, @p4", sqlParams) == 1; _context.Database.ExecuteSqlRaw("UpdateOrderStatus @p0, @p1", request.OrderId, OrderStatus.Paid); } if (success) { return(Unit.Value); } throw new Exception("Problem saving changes"); }
public async Task <IActionResult> Register(Student student) { if (ModelState.IsValid) { // Check if provided batch exist, if it does not return view with model error var existingBatch = _employeeRepository.GetAllBatches().Where(b => b.Id == student.BatchId).FirstOrDefault(b => b.Id == student.BatchId); if (existingBatch == null) { ModelState.AddModelError("", "Batch does not exist"); return(View(student)); } // If batch exist, create the student, add student to joint table var newStudent = _employeeRepository.AddStudent(student); // Get cost of student's program, and use it to create a payment record var costOfNewStudentsProgram = _employeeRepository.GetBatch(newStudent.BatchId).Programme.Cost; Payment payment = new Payment { StudentId = newStudent.StudentId, }; if (newStudent.Type == StudentType.ISA) { payment.Total = 1000000; } else { payment.Total = costOfNewStudentsProgram; } _payment.AddPayment(payment); //StudentBatch studentBatch = new StudentBatch //{ // BatchId = newStudent.BatchId, // StudentId = newStudent.StudentId //}; //var result = _db.StudentBatches.Add(studentBatch); var result = _db.StudentBatches.Add( new StudentBatch { BatchId = newStudent.BatchId, StudentId = newStudent.StudentId } ); await _db.SaveChangesAsync(); // This line gets all the batches a student belong to from the joint table var batches = _db.StudentBatches .Include(s => s.Batch).Where(s => s.StudentId == newStudent.StudentId).ToList(); // If student belongs to a batch, get the program for that batch if (batches != null) { var programs = new List <Programme>(); var list = new List <StudentCourse>(); foreach (var batch in batches) { programs.Add(_db.Programmes.Include(p => p.ProgrammeCourses).FirstOrDefault(p => p.ProgrammeId == batch.Batch.ProgrammeId)); } // After getting all the programs of a student, get the courses a student is suppose to have offerred or to offer from the // list of courses in each program foreach (var program in programs) { foreach (var course in program.ProgrammeCourses) { var sc = new StudentCourse { CourseId = course.CourseId, StudentId = newStudent.StudentId }; list.Add(sc); } } // Add the student course to the joint studentcourses joint table foreach (var itm in list) { _db.StudentCourses.Add(itm); await _db.SaveChangesAsync(); } } return(RedirectToAction("Index")); } return(View()); }