public void SaveToDatabase_ExistingPayment_CorrectId() { var payment = new Payment(); var dataAccess = new PaymentDataAccess(connectionCreator); dataAccess.SaveItem(payment); Assert.AreEqual(0, payment.Amount); var id = payment.Id; var amount = 789; payment.Amount = amount; Assert.AreEqual(id, payment.Id); Assert.AreEqual(amount, payment.Amount); }
public void SaveToDatabase_CreateAndUpdatePayment_CorrectlyUpdated() { var firstAmount = 5555555; var secondAmount = 222222222; var payment = new Payment { Amount = firstAmount }; var dataAccess = new PaymentDataAccess(connectionCreator); dataAccess.SaveItem(payment); Assert.AreEqual(firstAmount, dataAccess.LoadList().FirstOrDefault(x => x.Id == payment.Id).Amount); payment.Amount = secondAmount; dataAccess.SaveItem(payment); var categories = dataAccess.LoadList(); Assert.IsFalse(categories.Any(x => Math.Abs(x.Amount - firstAmount) < 0.1)); Assert.AreEqual(secondAmount, categories.First(x => x.Id == payment.Id).Amount); }
private void btnDelete_Click(object sender, EventArgs e) { // delete payments if (txtInvoiceNo.Text != null) { if (MessageBox.Show("Do you want to delete thid record ?", "Message", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { try { var payment = new Payment(); payment.InvoiceNo = txtInvoiceNo.Text; payment.IsRemoved = true; var result = PaymentDataAccess.deletePayment(payment); if (result == true) { MessageBox.Show("Payment record has been deleted successfully", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information); gridRefresh(); // call grid refresh method clearField(); // call clear field method } else { MessageBox.Show("Unable to delete payment record ", "Alert", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); } } catch (Exception ex) { MessageBox.Show("Failed : " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } else { MessageBox.Show("Enter invoice no. to proceed with delete process", "Message", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); } }
public PaymentController() { DataAccess = new PaymentDataAccess(); }
public PaymentService(PaymentDataAccess paymentDataAccess) { _paymentDataAccess = paymentDataAccess; }
private void btnSubmit_Click(object sender, EventArgs e) { try { var registrationId = txt_RegistrationId.Text; var courseId = txt_CourseId.Text; // get the last paid date var lastRecord = PaymentDataAccess.checkLastRecord(registrationId, courseId); var lastPaidDate = Convert.ToDateTime(lastRecord.PaidDate); var currentDate = Convert.ToDateTime(DateTime.Today); var totalDays = (currentDate - lastPaidDate).TotalDays; var totalMonths = Math.Truncate((totalDays % 365) / 28); if (totalMonths > 1) { DialogResult userInput = MessageBox.Show("Your last payment for " + txt_CourseName.Text + " course has been made on " + lastPaidDate + "\n" + "." + " Do you want to override process ?", "Alert", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (userInput == DialogResult.Yes) { var attendance = new Attendance(); attendance.Date = DateTime.Today.ToShortDateString(); attendance.RegistrationId = registrationId; attendance.StudentID = txtStudentName.Text; attendance.StudentName = txtStudentName.Text; attendance.CourseId = txt_CourseId.Text; attendance.CourseName = txt_CourseName.Text; attendance.LecturerId = txtLecturerID.Text; attendance.LecturerName = txtLecturerName.Text; var result = AttendanceDataAccess.markAttendance(attendance); if (result == true) { MessageBox.Show("Attendance has been recorded", "Message", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); //gridRefresh(); // call grid refresh method clearFields(); // call clear field method } else { MessageBox.Show("Unable to mark attendance", "Message", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); } } else { return; } } else { // mark attendance var attendance = new Attendance(); attendance.Date = DateTime.Today.ToShortDateString(); attendance.RegistrationId = registrationId; attendance.StudentID = txtStudentName.Text; attendance.StudentName = txtStudentName.Text; attendance.CourseId = txt_CourseId.Text; attendance.CourseName = txt_CourseName.Text; attendance.LecturerId = txtLecturerID.Text; attendance.LecturerName = txtLecturerName.Text; var result = AttendanceDataAccess.markAttendance(attendance); if (result == true) { MessageBox.Show("Attendance has been recorded", "Message", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); //gridRefresh(); // call grid refresh method clearFields(); // call clear field method } else { MessageBox.Show("Unable to mark attendance", "Message", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); } } } catch (Exception ex) { MessageBox.Show("Failed : " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void btnSave_Click(object sender, EventArgs e) { // add payment details try { var registrationId = txtRegistrationId.Text; var courseId = txtCourseId.Text; var payment = new Payment(); payment.InvoiceNo = txtInvoiceNo.Text; payment.RegistrationId = txtRegistrationId.Text; payment.StudentName = txtStudentName.Text; payment.CourseId = txtCourseId.Text; payment.CourseName = txtCourseName.Text; payment.Fee = Convert.ToDecimal(txtFee.Text); payment.Amount = Convert.ToDecimal(txtAmount.Text); payment.Balance = Convert.ToDecimal(txtBalance.Text); payment.LecturerId = txtLectuerId.Text; payment.LectuerName = txtLecturerName.Text; payment.PaidDate = datePayment.Value; payment.Invoicedate = Convert.ToDateTime(DateTime.Today.ToShortDateString()); payment.Username = Username; var record = PaymentDataAccess.addPayment(payment); if (record == true) { MessageBox.Show("Payment record has been saved successfully", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information); gridRefresh(); // call grid refresh method clearField(); // call clear field method // show invoice var invoice = new frm_printInvoice(payment); invoice.Show(); generateInvoiceNo(); // call generate invoice number method } else { MessageBox.Show("Unable to save payment record", "Message", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); } //var courseRecord = CourseEnrollmentDataAccess.findRegistrationDateByStudentId(registrationId, courseId); //paymentDate = courseRecord.RegisteredDate; // get course registered date as the payment required date //// check whether there's already payment records available for subject student id and course id //var result = PaymentDataAccess.checkRegistrationId(registrationId); //if (result == null) //{ // var payment = new Payment(); // payment.InvoiceNo = txtInvoiceNo.Text; // payment.RegistrationId = txtRegistrationId.Text; // payment.StudentName = txtStudentName.Text; // payment.CourseId = txtCourseId.Text; // payment.CourseName = txtCourseName.Text; // payment.Fee = Convert.ToDecimal(txtFee.Text); // payment.Amount = Convert.ToDecimal(txtAmount.Text); // payment.Balance = Convert.ToDecimal(txtBalance.Text); // payment.LecturerId = txtLectuerId.Text; // payment.LectuerName = txtLecturerName.Text; // payment.PaidDate = paymentDate; // payment.Invoicedate = Convert.ToDateTime(DateTime.Today.ToShortDateString()); // payment.Username = Username; //} //else //{ // // get the last paid date // var lastRecord = PaymentDataAccess.getLastRecord(registrationId, courseId); // var lastPaidDate = Convert.ToDateTime(lastRecord.PaidDate); // var currentDate = Convert.ToDateTime(DateTime.Today); // var totalDays = (currentDate - lastPaidDate).TotalDays; // var totalMonths = Math.Truncate((totalDays % 365) / 28); // if (totalMonths == 1) // { // // payment // var payment = new Payment(); // payment.InvoiceNo = txtInvoiceNo.Text; // payment.RegistrationId = txtRegistrationId.Text; // payment.StudentName = txtStudentName.Text; // payment.CourseId = txtCourseId.Text; // payment.CourseName = txtCourseName.Text; // payment.Fee = Convert.ToDecimal(txtFee.Text); // payment.Amount = Convert.ToDecimal(txtAmount.Text); // payment.Balance = Convert.ToDecimal(txtBalance.Text); // payment.LecturerId = txtLectuerId.Text; // payment.LectuerName = txtLecturerName.Text; // payment.PaidDate = lastPaidDate.AddMonths(1); // payment.Invoicedate = Convert.ToDateTime(DateTime.Today.ToShortDateString()); // payment.Username = Username; // var record = PaymentDataAccess.addPayment(payment); // if (record == true) // { // MessageBox.Show("Payment record has been saved successfully", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information); // gridRefresh(); // call grid refresh method // clearField(); // call clear field method // // show invoice // var invoice = new frm_printInvoice(payment); // invoice.Show(); // generateInvoiceNo(); // call generate invoice number method // } // else // { // MessageBox.Show("Unable to save payment record", "Message", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); // } // } // else // { // DialogResult userInput = MessageBox.Show("Your last payment for " + txtCourseName.Text + " course has been made on " + lastPaidDate + "\n" + "." + " Do you want to continue with payment process ?", "Alert", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question); // if (userInput == DialogResult.Yes) // { // // Yes - add a month to last paid date and save payment record // var payment = new Payment(); // payment.InvoiceNo = txtInvoiceNo.Text; // payment.RegistrationId = txtRegistrationId.Text; // payment.StudentName = txtStudentName.Text; // payment.CourseId = txtCourseId.Text; // payment.CourseName = txtCourseName.Text; // payment.Fee = Convert.ToDecimal(txtFee.Text); // payment.Amount = Convert.ToDecimal(txtAmount.Text); // payment.Balance = Convert.ToDecimal(txtBalance.Text); // payment.LecturerId = txtLectuerId.Text; // payment.LectuerName = txtLecturerName.Text; // payment.PaidDate = lastPaidDate.AddMonths(1); // payment.Invoicedate = Convert.ToDateTime(DateTime.Today.ToShortDateString()); // payment.Username = Username; // var record = PaymentDataAccess.addPayment(payment); // if (record == true) // { // MessageBox.Show("Payment record has been saved successfully", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information); // gridRefresh(); // call grid refresh method // clearField(); // call clear field method // // show invoice // var invoice = new frm_printInvoice(payment); // invoice.Show(); // generateInvoiceNo(); // call generate invoice number method // } // else // { // MessageBox.Show("Unable to save payment record", "Message", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); // } // } // else if (userInput == DialogResult.No) // { // // No - start a new payment flow and set the paid date to the current date // var payment = new Payment(); // payment.InvoiceNo = txtInvoiceNo.Text; // payment.RegistrationId = txtRegistrationId.Text; // payment.StudentName = txtStudentName.Text; // payment.CourseId = txtCourseId.Text; // payment.CourseName = txtCourseName.Text; // payment.Fee = Convert.ToDecimal(txtFee.Text); // payment.Amount = Convert.ToDecimal(txtAmount.Text); // payment.Balance = Convert.ToDecimal(txtBalance.Text); // payment.LecturerId = txtLectuerId.Text; // payment.LectuerName = txtLecturerName.Text; // payment.PaidDate = Convert.ToDateTime(DateTime.Today.ToShortDateString()); // payment.Invoicedate = Convert.ToDateTime(DateTime.Today.ToShortDateString()); // payment.Username = Username; // var record = PaymentDataAccess.addPayment(payment); // if (record == true) // { // MessageBox.Show("Payment record has been saved successfully", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information); // gridRefresh(); // call grid refresh method // clearField(); // call clear field method // // show invoice // var invoice = new frm_printInvoice(payment); // invoice.Show(); // generateInvoiceNo(); // call generate invoice number method // } // else // { // MessageBox.Show("Unable to save payment record", "Message", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); // } // } // else // { // clearField(); // call clear field method; // return; // } // } //} } catch (Exception ex) { MessageBox.Show("Failed : " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public void DeleteFromDatabase_PaymentToDelete_CorrectlyDelete() { var payment = new Payment { Note = "paymentToDelete", }; var dataAccess = new PaymentDataAccess(connectionCreator); dataAccess.SaveItem(payment); Assert.IsTrue(dataAccess.LoadList(x => x.Id == payment.Id).Any()); dataAccess.DeleteItem(payment); Assert.IsFalse(dataAccess.LoadList(x => x.Id == payment.Id).Any()); }
public PaymentService() { this.paymentDataAccess = new PaymentDataAccess(); }