// GET: MedicalPayment/Create public ActionResult Create(long? id) { MedicalPaymentViewModel model = new MedicalPaymentViewModel(); List<MedicalPaymentDetail> medicalPaymentList = new List<MedicalPaymentDetail>(); var appointment = db.Appointments.Include(l => l.PatientDetail).Where(a => a.ID == id).FirstOrDefault(); MedicalPaymentDetail medicalPayment = new MedicalPaymentDetail(); medicalPayment.Appointment = appointment; medicalPayment.Appointment_ID = appointment.ID; medicalPayment.Quantity = 1; model.MedicalPayment = medicalPayment; model.MedicalPayments = medicalPaymentList; List<DoctorName> doctornamelist = UtilityManager.GetLabDoctor(); ViewBag.MedicalPayment_Doctor_ID = new SelectList(doctornamelist, "ID", "Name"); ViewBag.MedicalPayment_PaymentMode_ID = new SelectList(db.PaymentModes, "ID", "Mode"); ViewBag.MedicalPayment_PaymentSection_ID = new SelectList(db.PaymentSections, "ID", "Name"); ViewBag.MedicalPayment_PaymentStatusID = new SelectList(db.PaymentStaus, "ID", "Details"); ViewBag.MedicalPayment_MedicalEquipmentID = new SelectList(db.MedicalEquipments, "ID", "EquipmentName"); return View(model); }
public async Task<ActionResult> Create(MedicalPaymentViewModel model) { if (ModelState.IsValid) { var currentUserId = User.Identity.GetUserId(); long customerId = 1; if (currentUserId != null) { var manager = new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(new ApplicationDbContext())); customerId = manager.FindById(currentUserId).HMSEmpID; } foreach (MedicalPaymentDetail item in model.MedicalPayments) { item.DiscountedBy = Convert.ToInt64(customerId); item.PaymentReceivedBy = Convert.ToInt64(customerId); item.PaymentReceivedDate = DateTime.Now; if (item.DueAmount == 0) { item.PaymentStatusID = 1; } else { item.PaymentStatusID = 3; } db.MedicalPaymentDetails.Add(item); } try { db.SaveChanges(); return RedirectToAction("Index"); } catch (Exception ex) { throw ex; } } List<DoctorName> doctornamelist = UtilityManager.GetLabDoctor(); ViewBag.MedicalPayment_Doctor_ID = new SelectList(doctornamelist, "ID", "Name", model.MedicalPayments.First().Doctor_ID); ViewBag.MedicalPayment_MedicalEquipmentID = new SelectList(db.MedicalEquipments, "ID", "EquipmentName", model.MedicalPayments.First().MedicalEquipmentID); ViewBag.MedicalPayment_PaymentMode_ID = new SelectList(db.PaymentModes, "ID", "Mode", model.MedicalPayments.First().PaymentMode_ID); ViewBag.MedicalPayment_PaymentSection_ID = new SelectList(db.PaymentSections, "ID", "Name", model.MedicalPayments.First().PaymentSection_ID); return View(model); }