public async Task <IActionResult> Create([Bind("MedicalreportName,ReportFile,MedicalreportId,PatientId")] MedicalReport medicalReports) { if (ModelState.IsValid) { _context.Add(medicalReports); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["MedicalreportId"] = new SelectList(_context.MedicalreportType, "MedicalreportId", "ReportType", medicalReports.MedicalreportId); ViewData["PatientId"] = new SelectList(_context.Patient, "PatientId", "Allergy", medicalReports.PatientId); return(View(medicalReports)); }
public async Task <IActionResult> Create([Bind("ApptId,ApptDate,AppointmentReason,PatientEmail,PatientId,VisitRecord,DoctorId")] Appointment appointment) { if (ModelState.IsValid) { var findbyemail = _context.Appointment.Where(c => c.PatientEmail == User.Identity.Name).Count(); //If the email is found, reject creating the appointment and redirect to the page that says unsuccessful if (findbyemail != 0) { return(View("AppointmentExists")); } //Add the user to misused user database if (User.IsInRole("Patient")) { if (!UserExists(User.Identity.Name)) { var newuser = new MisusedUser { UserEmail = User.Identity.Name, Misusedcount = 0 }; _context.MisusedUser.Add(newuser); await _context.SaveChangesAsync(); } } _context.Add(appointment); await _context.SaveChangesAsync(); //Remove from available time var appointment_context = _context.DoctorAvailability.Where(a => a.AvailableTime == appointment.ApptDate && a.DoctorId == appointment.DoctorId).FirstOrDefault(); _context.DoctorAvailability.Remove(appointment_context); await _context.SaveChangesAsync(); //Add to unavailable time var addtime = new DoctorUnavailability { DoctorId = appointment.DoctorId, Unavailable = appointment.ApptDate }; _context.DoctorUnavailability.Add(addtime); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["DoctorId"] = new SelectList(_context.Doctor, "DoctorId", "DoctorName", appointment.DoctorId); ViewData["PatientId"] = new SelectList(_context.Patient, "PatientId", "PatientEmail", appointment.PatientId); return(View(appointment)); }
public async Task <IActionResult> Create([Bind("PaymentDate,PaymentId,PaymentAmount,BillingId,ReceiveReceipt")] CashPayment cashPayment) { if (ModelState.IsValid) { _context.Add(cashPayment); await _context.SaveChangesAsync(); //Change status to paid var billing = await _context.Billing .FirstOrDefaultAsync(m => m.BillingId == cashPayment.BillingId); billing.Paid = true; await _context.SaveChangesAsync(); //Send receipt if (cashPayment.ReceiveReceipt == true) { var get_patient_id = _context.Billing.Where(c => c.BillingId == cashPayment.BillingId).FirstOrDefault().PatientId; var get_patient_email = _context.Patient.Where(c => c.PatientId == get_patient_id).FirstOrDefault().PatientEmail; var get_patient_name = _context.Patient.Where(c => c.PatientId == get_patient_id).FirstOrDefault().PatientName; /**//* SendReceipt receipt = new SendReceipt(); * receipt.Sendemail(get_patient_email, checkPayment.PaymentAmount, checkPayment.BillingId);*//**/ //Send an email //Sending email, make a different class file for this. var fromAddress = new MailAddress("*****@*****.**", "Healthcare Service"); var toAddress = new MailAddress(get_patient_email, get_patient_name); string messagebody = "You paid your invoice of amount " + cashPayment.PaymentAmount + " and billing Id " + cashPayment.BillingId; const string subject = "Receipt of Paymment"; string body = messagebody; var smtp = new SmtpClient { Host = "smtp.gmail.com", Port = 587, EnableSsl = true, DeliveryMethod = SmtpDeliveryMethod.Network, UseDefaultCredentials = false, Credentials = new System.Net.NetworkCredential(fromAddress.Address, "xrtwdhjqxqvsurfn") }; using (var message = new MailMessage(fromAddress, toAddress) { Subject = subject, Body = body }) { smtp.Send(message); } } return(View("CashPaymentSuccessful")); } ViewData["BillingId"] = new SelectList(_context.Billing, "BillingId", "BillingId", cashPayment.BillingId); return(View("CashPaymentUnSuccessful")); } /* * // GET: CashPayments/Edit/5 * public async Task<IActionResult> Edit(int? id) * { * if (id == null) * { * return NotFound(); * } * * var cashPayment = await _context.CashPayment.FindAsync(id); * if (cashPayment == null) * { * return NotFound(); * } * ViewData["BillingId"] = new SelectList(_context.Billing, "BillingId", "BillingId", cashPayment.BillingId); * return View(cashPayment); * } * * // POST: CashPayments/Edit/5 * // To protect from overposting attacks, enable the specific properties you want to bind to, for * // more details, see http://go.microsoft.com/fwlink/?LinkId=317598. * [HttpPost] * [ValidateAntiForgeryToken] * public async Task<IActionResult> Edit(int id, [Bind("PaymentDate,PaymentId,PaymentAmount,BillingId,ReceiveReceipt")] CashPayment cashPayment) * { * if (id != cashPayment.PaymentId) * { * return NotFound(); * } * * if (ModelState.IsValid) * { * try * { * _context.Update(cashPayment); * await _context.SaveChangesAsync(); * } * catch (DbUpdateConcurrencyException) * { * if (!CashPaymentExists(cashPayment.PaymentId)) * { * return NotFound(); * } * else * { * throw; * } * } * return RedirectToAction(nameof(Index)); * } * ViewData["BillingId"] = new SelectList(_context.Billing, "BillingId", "BillingId", cashPayment.BillingId); * return View(cashPayment); * } * * // GET: CashPayments/Delete/5 * public async Task<IActionResult> Delete(int? id) * { * if (id == null) * { * return NotFound(); * } * * var cashPayment = await _context.CashPayment * .Include(c => c.Billing) * .FirstOrDefaultAsync(m => m.PaymentId == id); * if (cashPayment == null) * { * return NotFound(); * } * * return View(cashPayment); * } * * // POST: CashPayments/Delete/5 * [HttpPost, ActionName("Delete")] * [ValidateAntiForgeryToken] * public async Task<IActionResult> DeleteConfirmed(int id) * { * var cashPayment = await _context.CashPayment.FindAsync(id); * _context.CashPayment.Remove(cashPayment); * await _context.SaveChangesAsync(); * return RedirectToAction(nameof(Index)); * } * * private bool CashPaymentExists(int id) * { * return _context.CashPayment.Any(e => e.PaymentId == id); * }*/ } }
//Card payment using stripe public async Task <IActionResult> Charge(int?id, string stripeEmail, string stripeToken) { if (id == null) { return(NotFound()); } var billing = await _context.Billing .Include(b => b.Patient) .FirstOrDefaultAsync(m => m.BillingId == id); if (billing == null) { return(NotFound()); } //Create stripe charge var customers = new CustomerService(); var charges = new ChargeService(); var customer = customers.Create(new CustomerCreateOptions { Email = stripeEmail, Source = stripeToken, }); var charge = charges.Create(new ChargeCreateOptions { Amount = (long)billing.BillingAmount * 100, Description = "Invoice", Currency = "usd", Customer = customer.Id, ReceiptEmail = stripeEmail }); // if (charge.Status == "succeeded") { //Add payment record to card payment if (ModelState.IsValid) { /// Use charge id as reference no var newpayment = new CardPayment { PaymentDate = DateTime.Now, PaymentAmount = billing.BillingAmount, BillingId = (int)id, ReferenceNo = charge.Id }; _context.Add(newpayment); await _context.SaveChangesAsync(); //Update the paid starus in the invoice billing.Paid = true; await _context.SaveChangesAsync(); //Send an email //Sending email, make a different class file for this. var fromAddress = new MailAddress("*****@*****.**", "Utsav"); var toAddress = new MailAddress(charge.ReceiptEmail); string messagebody = "You paid your invoice of amount " + billing.BillingAmount + " and billing Id " + billing.BillingId + ". Your charge id is " + charge.Id; const string subject = "Receipt of Paymment"; string body = messagebody; var smtp = new SmtpClient { Host = "smtp.gmail.com", Port = 587, EnableSsl = true, DeliveryMethod = SmtpDeliveryMethod.Network, UseDefaultCredentials = false, Credentials = new System.Net.NetworkCredential(fromAddress.Address, "xrtwdhjqxqvsurfn") }; using (var message = new MailMessage(fromAddress, toAddress) { Subject = subject, Body = body }) { smtp.Send(message); } } return(View("chargesuccessful")); } else { return(View("Chargeunsuccessful")); } }
public async Task <IActionResult> Create([Bind("CheckNo,PaymentAmount,PaymentDate,BillingId,ReceiveReceipt")] CheckPayment checkPayment) { if (ModelState.IsValid) { Console.WriteLine("Check Payment" + checkPayment.BillingId + checkPayment.PaymentAmount ); _context.Add(checkPayment); await _context.SaveChangesAsync(); //Update Paid Status in invoice var billing = await _context.Billing .FirstOrDefaultAsync(m => m.BillingId == checkPayment.BillingId); billing.Paid = true; await _context.SaveChangesAsync(); //Send receipt if (checkPayment.ReceiveReceipt == true) { var get_patient_id = _context.Billing.Where(c => c.BillingId == checkPayment.BillingId).FirstOrDefault().PatientId; var get_patient_email = _context.Patient.Where(c => c.PatientId == get_patient_id).FirstOrDefault().PatientEmail; var get_patient_name = _context.Patient.Where(c => c.PatientId == get_patient_id).FirstOrDefault().PatientName; /* SendReceipt receipt = new SendReceipt(); * receipt.Sendemail(get_patient_email, checkPayment.PaymentAmount, checkPayment.BillingId);*/ //Send an email //Sending email, make a different class file for this. var fromAddress = new MailAddress("*****@*****.**", "Healthcare Service"); var toAddress = new MailAddress(get_patient_email, get_patient_name); string messagebody = "You paid your invoice of amount " + checkPayment.PaymentAmount + " and billing Id " + checkPayment.BillingId; const string subject = "Receipt of Paymment"; string body = messagebody; var smtp = new SmtpClient { Host = "smtp.gmail.com", Port = 587, EnableSsl = true, DeliveryMethod = SmtpDeliveryMethod.Network, UseDefaultCredentials = false, Credentials = new System.Net.NetworkCredential(fromAddress.Address, "xrtwdhjqxqvsurfn") }; using (var message = new MailMessage(fromAddress, toAddress) { Subject = subject, Body = body }) { smtp.Send(message); } Console.WriteLine(get_patient_email); Console.WriteLine(get_patient_name); } return(View("CheckPaymentSuccessful")); } ViewData["BillingId"] = new SelectList(_context.Billing, "BillingId", "BillingId", checkPayment.BillingId); return(View("CheckPaymentSuccessful")); }